Maven,Spring,Hibernate,Flex,PureMVC整合(一)

主要参考文章:

1.《构建全栈式Flex、BlazeDS和Spring集成解决方案》
2. http://www.iteye.com/topic/392836

      最近和朋友正策划一个记账的小型项目,想用Flex来做前端开发。以前有看过Flex方面的教程,这次动手构建这个项目还真花了不少时间,因为像我这么构建的文章几乎没有。按理说上面2篇参考文章都能构建好项目,但是我想用Maven的人肯定很多,"风雪涟漪"的构建没用到Maven,而《构建全栈式Flex、BlazeDS和Spring集成解决方案》教程里连Flex都用Maven构建,不能说不好,但是目前FlexBuilder3根本不支持Maven构建的项目,所以根本无法用此IDE,对于大多数人来说做开发还是比较依赖IDE的,所以我各取所长构建自己的项目。好了,废话不多说,我们开始。
     在Java端用Spring+hibernate搭基本骨架,我有个兄弟之前做了个Flex项目,Java端用Spring+hibernate+Struts2架构,然后用Flex的HttpService来请求数据。但我总觉得Struts2在这里显得很多余,完全可以用Spring+BlazeDS与Flex经行交互。

 

所需要的开发环境 :

1.Eclipse3.4(J2EE版本)

2.Flex Builder 3

3.Maven2.0.9

(说明:2.1.0和2.2.0两个版本对flex-compiler-mojo支持有Bug,如果完全用《构建全栈式Flex、BlazeDS和Spring集成解决方案》来构建,建议使用2.0.9的Maven版本)

 

一、利用Maven构建Web应用

打开Cmd,定位到你的工作空间,运行下面命令

mvn archetype:create -DgroupId=com.zhjj.zhangben -DartifactId=zhengben

然后加入eclipse支持,运行mvn eclipse:eclipse

现在你可以用eclipse打开这个基础应用了

 

二、加入spring,hibernate,blazeds,spring-flex依赖

<!-- 添加spring依赖 -->
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring</artifactId>
   <version>${spring.version}</version>
  </dependency>
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-webmvc</artifactId>
   <version>${spring.version}</version>
  </dependency>
  <dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-test</artifactId>
   <version>${spring.version}</version>
   <scope>test</scope>
  </dependency>
  <dependency>
   <groupId>org.aspectj</groupId>
   <artifactId>aspectjrt</artifactId>
   <version>1.5.4</version>
  </dependency>
  <dependency>
   <groupId>org.aspectj</groupId>
   <artifactId>aspectjweaver</artifactId>
   <version>1.5.4</version>
  </dependency>
  <!-- 添加hibernate依赖 -->
  <dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate-annotations</artifactId>
   <version>${hibernate.annotations.version}</version>
  </dependency>
  <dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate-commons-annotations</artifactId>
   <version>${hibernate.annotations.version}</version>
  </dependency>
  <dependency>
   <groupId>${jdbc.groupId}</groupId>
   <artifactId>${jdbc.artifactId}</artifactId>
   <version>${jdbc.version}</version>
  </dependency>
  <!-- 添加blazeds依赖 -->
  <dependency> 
   <groupId>com.adobe.blazeds</groupId> 
   <artifactId>blazeds-common</artifactId> 
   <version>3.0.0.544</version> 
  </dependency> 
  <dependency> 
   <groupId>com.adobe.blazeds</groupId> 
   <artifactId>blazeds-core</artifactId> 
   <version>3.0.0.544</version> 
  </dependency> 
  <dependency> 
   <groupId>com.adobe.blazeds</groupId> 
   <artifactId>blazeds-remoting</artifactId> 
   <version>3.0.0.544</version> 
  </dependency> 
  <dependency> 
   <groupId>backport-util-concurrent</groupId> 
   <artifactId>backport-util-concurrent</artifactId> 
   <version>3.1</version> 
  </dependency>
  <!-- spring-flex -->
  <dependency> 
   <groupId>org.springframework</groupId> 
   <artifactId>spring-flex</artifactId> 
   <version>1.0.0.RELEASE</version> 
  </dependency>

  

 需要说明的是,目前为止spring-flex还没有以公共的Maven仓库方式公开,所以要到http://www.springsource.org/spring-flex 去下载然后自己加到本地仓库中。

 

三、以下几个依赖包都不可或缺,否则会报很多莫名其妙的错误(这些错误我Google,Baidu了个好几天才解决,我哭啊。。。。)

<dependency>
   <groupId>org.codehaus.jackson</groupId>
   <artifactId>jackson-core-asl</artifactId>
   <version>0.9.9-6</version>
  </dependency>
  <!-- 
   cglib(Code Generation Library)是一个强大的,高性能,高质量的Code生成类库。它可以在运行期扩展Java类与实现Java接口。
   cglib封装了asm,可以在运行期动态生成新的class。
   cglib用于AOP,jdk中的proxy必须基于接口,cglib却没有这个限制
   -->
  <dependency>
   <groupId>cglib</groupId>
   <artifactId>cglib</artifactId>
   <version>2.2</version>
  </dependency>
  <!-- xalan是一套xslt处理器,用来将XML文件转换为HTML,TEXT和XML等其他类型文件格式 -->
  <dependency>
   <groupId>xalan</groupId>
   <artifactId>xalan</artifactId>
   <version>2.7.1</version>
  </dependency>
  <dependency> 
   <groupId>javax.servlet</groupId> 
   <artifactId>servlet-api</artifactId> 
   <version>2.5</version> 
   <scope>provided</scope> 
  </dependency>

  

四、增加几个插件

<plugins>

<!-- 编译用的 -->
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
     <source>1.5</source>
     <target>1.5</target>
    </configuration>
   </plugin>

<!-- 用来在Java中生成数据库表-->
   <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>hibernate3-maven-plugin</artifactId>
    <version>2.1</version>
    <configuration>
     <components>
      <component>
       <name>hbm2ddl</name>
       <implementation>annotationconfiguration</implementation>
       <!-- Use 'jpaconfiguration' if you're using JPA. -->
       <!--<implementation>jpaconfiguration</implementation>-->
      </component>
     </components>
     <componentProperties>
      <drop>true</drop>
      <jdk5>true</jdk5>
      <propertyfile>target/classes/jdbc.properties</propertyfile>
      <skip>${maven.test.skip}</skip>
     </componentProperties>
    </configuration>
    <executions>
     <execution>
      <phase>process-test-resources</phase>
      <goals>
       <goal>hbm2ddl</goal>
      </goals>
     </execution>
    </executions>
    <dependencies>
     <dependency>
      <groupId>${jdbc.groupId}</groupId>
      <artifactId>${jdbc.artifactId}</artifactId>
      <version>${jdbc.version}</version>
     </dependency>
    </dependencies>
   </plugin>
   <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>dbunit-maven-plugin</artifactId>
    <version>1.0-beta-1</version>
    <configuration>
     <dataTypeFactoryName>${dbunit.dataTypeFactoryName}</dataTypeFactoryName>
     <driver>${jdbc.driverClassName}</driver>
     <username>${jdbc.username}</username>
     <password>${jdbc.password}</password>
     <url>${jdbc.url}</url>
     <src>src/test/resources/sample-data.xml</src>
     <type>${dbunit.operation.type}</type>
     <schema>${dbunit.schema}</schema>
     <skip>${maven.test.skip}</skip>
    </configuration>
    <executions>
     <execution>
      <id>test-compile</id>
      <phase>test-compile</phase>
      <goals>
       <goal>operation</goal>
      </goals>
     </execution>
     <execution>
      <!-- Runs before integration tests and jetty:run-war -->
      <id>test</id>
      <phase>test</phase>
      <goals>
       <goal>operation</goal>
      </goals>
     </execution>
    </executions>
    <dependencies>
     <dependency>
      <groupId>${jdbc.groupId}</groupId>
      <artifactId>${jdbc.artifactId}</artifactId>
      <version>${jdbc.version}</version>
     </dependency>
    </dependencies>
   </plugin>
<!-- Jetty插件,测试服务器 -->
   <plugin>
    <groupId>org.mortbay.jetty</groupId>
    <artifactId>maven-jetty-plugin</artifactId>
    <version>6.1.6</version>
    <configuration>
     <contextPath>/zhangben</contextPath>
     <scanIntervalSeconds>3</scanIntervalSeconds>
     <connectors>
      <connector
       implementation="org.mortbay.jetty.bio.SocketConnector">
       <port>8080</port>
       <maxIdleTime>60000</maxIdleTime>
      </connector>
     </connectors>
     <scanTargetPatterns>
      <scanTargetPattern>
       <directory>
        src/main/webapp/WEB-INF
       </directory>
       <excludes>
        <exclude>**/*.jsp</exclude>
       </excludes>
       <includes>
        <include>**/*.properties</include>
        <include>*.xml</include>
       </includes>
      </scanTargetPattern>
      <scanTargetPattern>
       <directory>src/main/resources</directory>
       <includes>
        <include>*.properties</include>
        <include>*.xml</include>
       </includes>
      </scanTargetPattern>
     </scanTargetPatterns>
    </configuration>
   </plugin>
<!-- eclipse插件 -->
   <plugin>
    <artifactId>maven-eclipse-plugin</artifactId>
    <version>2.5.1</version>
    <configuration>
     <additionalProjectnatures>
      <projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
     </additionalProjectnatures>
     <additionalBuildcommands>
      <buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
     </additionalBuildcommands>
     <downloadSources>true</downloadSources>
     <downloadJavadocs>true</downloadJavadocs>
     <wtpversion>1.5</wtpversion>
    </configuration>
   </plugin>
  </plugins>

 

  

 

要下班了,明天继续!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值