整合spring roo,maven,mybatis,spring-flex,blazeds,mysql

时间:2022-11-04 06:26:40

1.      下载spring roo,设置环境变量ROO_HOME,和path,classpath.

使用CMD命令行找到工作区间,新建工程目录转到工程目录;mkdir ten-minutes

cdten-minutes

2.      project--topLevelPackage com.tenminutes

3.      roo>jpa setup --provider HIBERNATE--database HYPERSONIC_IN_MEMORY

4.      roo>hint

5.      roo>entity jpa --class ~.Timer--testAutomatically

6.      roo>hint

7.      roo>field string --fieldName message--notNull

8.      roo>hint web mvc

9.      roo>web mvc setup

10.  roo>web mvc all --package ~.web

11.  roo>selenium test --controller~.web.TimerController

12.  roo>perform tests

13.  roo>perform package

14.  roo>perform eclipse

15.  roo>quit

16.  $mvn tomcat:run

添加<blazeds.version>4.0.0.14931</blazeds.version>为项目添加blazeds开发版本号

2.添加mybatis开发生成器:<!--mybatisgenerator -->

<repository>

<id>mybatis-snapshot</id>

<name>MyBatisSnapshot Repository</name>

<url>https://oss.sonatype.org/content/repositories/snapshots</url>

</repository>

3.添加类库依赖<dependency>

<groupId>org.mybatis</groupId>

<artifactId>mybatis</artifactId>

<version>3.0.1</version>

</dependency>

<dependency>

<groupId>org.mybatis</groupId>

<artifactId>mybatis-spring</artifactId>

<version>1.1.0</version>

</dependency>

<!-- springflex-->

<dependency>

<groupId>org.springframework.flex</groupId>

<artifactId>spring-flex-core</artifactId>

<version>1.5.2.RELEASE</version>

</dependency>

<!-- Blazeds-->

<dependency>

<groupId>com.adobe.blazeds</groupId>

<artifactId>blazeds-core</artifactId>

<version>${blazeds.version}</version>

</dependency>

<dependency>

<groupId>com.adobe.blazeds</groupId>

<artifactId>blazeds-common</artifactId>

<version>${blazeds.version}</version>

</dependency>

<dependency>

<groupId>com.adobe.blazeds</groupId>

<artifactId>blazeds-proxy</artifactId>

<version>${blazeds.version}</version>

</dependency>

<dependency>

<groupId>com.adobe.blazeds</groupId>

<artifactId>blazeds-remoting</artifactId>

<version>${blazeds.version}</version>

</dependency>

4.mybatis插件<plugin>

<groupId>org.mybatis.generator</groupId>

<artifactId>mybatis-generator-maven-plugin</artifactId>

<version>1.3.1</version>

<configuration>

<verbose>true</verbose>

<overwrite>true</overwrite>

</configuration>

</plugin>

5.可能需要转到Blazeds目录将一些类库打进去maven类库,命令行如下:mvn install:install-file -Dpackaging=jar -DgroupId=com.adobe.blazeds -Dversion=4.0.0.14931 -DartifactId=blazeds-common -Dfile=flex-messaging-common.jar 

mvn install:install-file -Dpackaging=jar -DgroupId=com.adobe.blazeds-Dversion=4.0.0.14931 -DartifactId=blazeds-core -Dfile=flex-messaging-core.jar

mvn install:install-file -Dpackaging=jar -DgroupId=com.adobe.blazeds-Dversion=4.0.0.14931 -DartifactId=blazeds-opt -Dfile=flex-messaging-opt.jar

mvn install:install-file -Dpackaging=jar -DgroupId=com.adobe.blazeds-Dversion=4.0.0.14931 -DartifactId=blazeds-proxy -Dfile=flex-messaging-proxy.jar

mvn install:install-file -Dpackaging=jar -DgroupId=com.adobe.blazeds-Dversion=4.0.0.14931 -DartifactId=blazeds-remoting -Dfile=flex-messaging-remoting.jar

mvn install:install-file -Dpackaging=jar -DgroupId=com.adobe.blazeds-Dversion=4.0.0.14931 -DartifactId=blazeds-rds-server -Dfile=flex-rds-server.jar

修改一下propertis,数据库配置文件,格式如下:#Updated at Mon Apr 09 09:15:39 CST 2012

#Mon Apr09 09:15:39 CST 2012

database.driverClassName=com.mysql.jdbc.Driver

database.url=jdbc\:mysql\://localhost\:3306/managerplatform

database.username=root

database.password=qwer123456

使用 database introspect --schemafeedback_schema 来内部检查数据库模式。

完成数据库模式内部检查以后,您可以用 database reverse engineer --schemafeedback_schema --package ~.domain 对模式进行反向工程。

准备好mybatis的生成器配置文件,利用命令行运行mvn mybatis-generator:generate。

6.上下文配置:<?xmlversion="1.0"encoding="UTF-8"standalone="no"?>

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:aop="http://www.springframework.org/schema/aop"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:jee="http://www.springframework.org/schema/jee"

xmlns:tx="http://www.springframework.org/schema/tx"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop-3.1.xsd        http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans-3.1.xsd        http://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context-3.1.xsd         http://www.springframework.org/schema/jeehttp://www.springframework.org/schema/jee/spring-jee-3.1.xsd        http://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx-3.1.xsd">

<context:property-placeholderlocation="classpath*:META-INF/spring/*.properties"/>

<!-- enable autowire-->

<context:annotation-config/>

<context:component-scanbase-package="com.bingya">

</context:component-scan>

<tx:annotation-driven/>

<beanclass="org.springframework.jdbc.datasource.DriverManagerDataSource"

id="dataSource">

<propertyname="driverClassName"value="${database.driverClassName}"/>

<propertyname="url"value="${database.url}"/>

<propertyname="username"value="${database.username}"/>

<propertyname="password"value="${database.password}"/>

</bean>

<beanid="transactionManager"

class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

<propertyname="dataSource"ref="dataSource"/>

</bean>

<!-- define the SqlSessionFactory-->

<beanid="sqlSessionFactory"class="org.mybatis.spring.SqlSessionFactoryBean">

<propertyname="dataSource"ref="dataSource"/>

<propertyname="typeAliasesPackage"value="com.bingya"/>

</bean>

<!-- scan formappers andlet them beautowired -->

<beanclass="org.mybatis.spring.mapper.MapperScannerConfigurer">

<propertyname="basePackage"value="com.bingya"/>

</bean>

</beans>

web.xml

  1. <?xml version="1.0" encoding="ISO-8859-1" standalone="no"?>
  2. <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. version="2.5"
  4. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  5. <display-name>SpringRoo</display-name>
  6. <description>Roo generated SpringRoo application</description>
  7. <context-param>
  8. <param-name>contextConfigLocation</param-name>
  9. <param-value>classpath*:META-INF/spring/applicationContext*.xml</param-value>
  10. </context-param>
  11. <!-- Creates the Spring Container shared by all Servlets and Filters -->
  12. <listener>
  13. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  14. </listener>
  15. <!-- Handles Spring requests -->
  16. <servlet>
  17. <servlet-name>SpringRoo</servlet-name>
  18. <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  19. <init-param>
  20. <param-name>contextConfigLocation</param-name>
  21. <param-value>WEB-INF/spring/webmvc-config.xml</param-value>
  22. </init-param>
  23. <load-on-startup>1</load-on-startup>
  24. </servlet>
  25. <servlet-mapping>
  26. <servlet-name>SpringRoo</servlet-name>
  27. <url-pattern>/messagebroker/*</url-pattern>
  28. </servlet-mapping>
  29. </web-app>