• 配置文件总结


    永久解决Jdk1.7

    Maven的插件  

       <!-- jdk1.7 -->

    <build>

    <plugins>

    <plugin>

    <groupId>org.apache.maven.plugins</groupId>

    <artifactId>maven-compiler-plugin</artifactId>

    <version>3.2</version>

    <configuration>

    <source>1.7</source>

    <target>1.7</target>

    <encoding>UTF-8</encoding>

    </configuration>

    </plugin>

    </plugins>

    </build>

     

     

    导入所有Jar

    2.1 父工程Parent

    Spring 4.1.3

    Mybatis 3.2.7

    Springmvc 4.1.3

    <!-- 设置统一控制版本 -->

    <properties>

    <java-version>1.7</java-version>

    <junit-version>4.12</junit-version>

    <spring.version>4.1.3.RELEASE</spring.version>

    <jackson.version>2.4.2</jackson.version>

    <mysql-connector-java-version>5.1.8</mysql-connector-java-version>

    <org.mybatis-version>3.2.7</org.mybatis-version>

    <org.mybatis-spring-version>1.2.2</org.mybatis-spring-version>

    <opensymphony-version>2.4.2</opensymphony-version>

    <freemarker-version>2.3.18</freemarker-version>

    <druid.version>1.0.9</druid.version>

    <commons-collections-version>1.0</commons-collections-version>

    <commons-fileupload-version>1.2.2</commons-fileupload-version>

    <org.apache.commons-version>3.1</org.apache.commons-version>

    <commons-codec-version>1.6</commons-codec-version>

    <dom4j-version>1.6.1</dom4j-version>

    <javax.servlet-version>1.2</javax.servlet-version>

    <aspectjweaver-version>1.6.6</aspectjweaver-version>

    <slf4j-log4j12-version>1.6.6</slf4j-log4j12-version>

    <log4j-version>1.2.16</log4j-version>

    <javax.servlet-jsp-version>2.0</javax.servlet-jsp-version>

    <cglib-version>2.2.2</cglib-version>

    <slf4j-api-version>1.6.6</slf4j-api-version>

    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    </properties>

    <!-- 依赖管理 版本号 -->

    <!-- 设置统一依赖管理、不强行依赖 -->

    <dependencyManagement>

    <dependencies>

    <!-- with junit4.8.2 -->

    <dependency>

    <groupId>junit</groupId>

    <artifactId>junit</artifactId>

    <version>${junit-version}</version>

    <type>jar</type>

    </dependency>

    <!-- Spring -->

    <dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-context</artifactId>

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

    </dependency>

    <dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-beans</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-jdbc</artifactId>

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

    </dependency>

    <dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-aspects</artifactId>

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

    </dependency>

    <dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-test</artifactId>

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

    </dependency>

    <dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-context-support</artifactId>

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

    </dependency>

    <dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-jms</artifactId>

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

    </dependency>

    <!-- Jackson Json处理工具包 -->

    <dependency>

    <groupId>com.fasterxml.jackson.core</groupId>

    <artifactId>jackson-databind</artifactId>

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

    </dependency>

    <!--freemarker -->

    <dependency>

    <groupId>org.freemarker</groupId>

    <artifactId>freemarker</artifactId>

    <version>2.3.18</version>

    </dependency>

    <!-- with mybatis-spring -->

    <dependency>

    <groupId>org.mybatis</groupId>

    <artifactId>mybatis</artifactId>

    <version>${org.mybatis-version}</version>

    </dependency>

    <dependency>

    <groupId>org.mybatis</groupId>

    <artifactId>mybatis-spring</artifactId>

    <version>${org.mybatis-spring-version}</version>

    </dependency>

    <!-- jdbc driver -->

    <dependency>

    <groupId>mysql</groupId>

    <artifactId>mysql-connector-java</artifactId>

    <version>${mysql-connector-java-version}</version>

    </dependency>

    <!-- 连接池 -->

    <dependency>

    <groupId>com.alibaba</groupId>

    <artifactId>druid</artifactId>

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

    </dependency>

    <!-- apache commons jar -->

    <dependency>

    <groupId>commons-collections</groupId>

    <artifactId>commons-collections</artifactId>

    <version>${commons-collections-version}</version>

    </dependency>

    <dependency>

    <groupId>commons-fileupload</groupId>

    <artifactId>commons-fileupload</artifactId>

    <version>${commons-fileupload-version}</version>

    </dependency>

    <dependency>

    <groupId>org.apache.commons</groupId>

    <artifactId>commons-lang3</artifactId>

    <version>${org.apache.commons-version}</version>

    </dependency>

    <dependency>

    <groupId>commons-codec</groupId>

    <artifactId>commons-codec</artifactId>

    <version>${commons-codec-version}</version>

    </dependency>

    <!-- analyze xml use dom4j -->

    <dependency>

    <groupId>dom4j</groupId>

    <artifactId>dom4j</artifactId>

    <version>${dom4j-version}</version>

    </dependency>

    <!-- jstl标签 -->

    <dependency>

    <groupId>jstl</groupId>

    <artifactId>jstl</artifactId>

    <version>1.2</version>

    </dependency>

    <dependency>

    <groupId>taglibs</groupId>

    <artifactId>standard</artifactId>

    <version>1.1.2</version>

    </dependency>

    <dependency>

    <groupId>org.slf4j</groupId>

    <artifactId>slf4j-log4j12</artifactId>

    <version>1.6.6</version>

    </dependency>

    <dependency>

    <groupId>log4j</groupId>

    <artifactId>log4j</artifactId>

    <version>1.2.17</version>

    </dependency>

    <dependency>

    <groupId>org.slf4j</groupId>

    <artifactId>slf4j-api</artifactId>

    <version>1.6.6</version>

    </dependency>

    <dependency>

    <groupId>javax.activation</groupId>

    <artifactId>activation</artifactId>

    <version>1.1.1</version>

    </dependency>

    <dependency>

    <groupId>cglib</groupId>

    <artifactId>cglib</artifactId>

    <version>${cglib-version}</version>

    </dependency>

    <dependency>

    <groupId>net.fckeditor</groupId>

    <artifactId>java-core</artifactId>

    <version>2.6</version>

    </dependency>

    <dependency>

    <groupId>org.json</groupId>

    <artifactId>json</artifactId>

    <version>20131018</version>

    </dependency>

    <!--page -->

    <dependency>

    <groupId>com.babasport</groupId>

    <artifactId>page</artifactId>

    <version>1.0</version>

    </dependency>

    <!-- solrJ -->

    <dependency>

    <groupId>org.apache.solr</groupId>

    <artifactId>solr-solrj</artifactId>

    <version>4.10.3</version>

    </dependency>

    <!-- jedis Java接口 -->

    <dependency>

    <groupId>redis.clients</groupId>

    <artifactId>jedis</artifactId>

    <version>2.6.2</version>

    <type>jar</type>

    </dependency>

    <!-- FastDFS client -->

    <dependency>

    <groupId>fastdfs_client</groupId>

    <artifactId>fastdfs_client</artifactId>

    <version>1.20</version>

    </dependency>

    <dependency>

    <groupId>org.jboss.netty</groupId>

    <artifactId>netty</artifactId>

    <version>3.2.5.Final</version>

    </dependency>

    <dependency>

    <groupId>com.alibaba</groupId>

    <artifactId>dubbo</artifactId>

    <version>2.5.3</version>

    </dependency>

    <dependency>

    <groupId>com.alibaba</groupId>

    <artifactId>fastjson</artifactId>

    <version>1.1.41</version>

    </dependency>

    <!-- Zookeeper 用于分布式服务管理 -->

    <dependency>

    <groupId>com.github.sgroschupf</groupId>

    <artifactId>zkclient</artifactId>

    <version>0.1</version>

    </dependency>

    <dependency>

    <groupId>org.apache.zookeeper</groupId>

    <artifactId>zookeeper</artifactId>

    <version>3.4.6</version>

    </dependency>

    <!-- Zookeeper 用于分布式服务管理 end -->

    <!-- Active MQ 开始 -->

    <dependency>

    <groupId>org.apache.activemq</groupId>

    <artifactId>activemq-all</artifactId>

    <version>5.8.0</version>

    </dependency>

    <dependency>

    <groupId>org.apache.activemq</groupId>

    <artifactId>activemq-pool</artifactId>

    <version>5.8.0</version>

    </dependency>

    <!-- Active MQ 结束 -->

    </dependencies>

    </dependencyManagement>

    <dependencies>

    <!-- Tomcat7 servlet-api -->

    <dependency>

    <groupId>org.apache.tomcat</groupId>

    <artifactId>tomcat-jsp-api</artifactId>

    <version>7.0.47</version>

    <scope>provided</scope>

    </dependency>

    </dependencies>

    2.2 Babasport-common

    <!-- 依赖管理之后台 -->

    <dependencies>

    <!-- with junit4.12 -->

    <dependency>

    <groupId>junit</groupId>

    <artifactId>junit</artifactId>

    </dependency>

    <!-- Spring -->

    <dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-context</artifactId>

    </dependency>

    <dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-beans</artifactId>

    </dependency>

    <dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-webmvc</artifactId>

    </dependency>

    <dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-jdbc</artifactId>

    </dependency>

    <dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-aspects</artifactId>

    </dependency>

    <dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-test</artifactId>

    </dependency>

    <dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-context-support</artifactId>

    </dependency>

    <dependency>

    <groupId>org.springframework</groupId>

    <artifactId>spring-jms</artifactId>

    </dependency>

    <!-- Jackson Json处理工具包 -->

    <dependency>

    <groupId>com.fasterxml.jackson.core</groupId>

    <artifactId>jackson-databind</artifactId>

    </dependency>

    <!--freemarker -->

    <dependency>

    <groupId>org.freemarker</groupId>

    <artifactId>freemarker</artifactId>

    </dependency>

    <!-- with mybatis-spring -->

    <dependency>

    <groupId>org.mybatis</groupId>

    <artifactId>mybatis</artifactId>

    </dependency>

    <dependency>

    <groupId>org.mybatis</groupId>

    <artifactId>mybatis-spring</artifactId>

    </dependency>

    <!-- jdbc driver -->

    <dependency>

    <groupId>mysql</groupId>

    <artifactId>mysql-connector-java</artifactId>

    </dependency>

    <!-- 连接池 -->

    <dependency>

    <groupId>com.alibaba</groupId>

    <artifactId>druid</artifactId>

    </dependency>

    <!-- apache commons jar -->

    <dependency>

    <groupId>commons-collections</groupId>

    <artifactId>commons-collections</artifactId>

    </dependency>

    <dependency>

    <groupId>commons-fileupload</groupId>

    <artifactId>commons-fileupload</artifactId>

    </dependency>

    <dependency>

    <groupId>org.apache.commons</groupId>

    <artifactId>commons-lang3</artifactId>

    </dependency>

    <dependency>

    <groupId>commons-codec</groupId>

    <artifactId>commons-codec</artifactId>

    </dependency>

    <!-- analyze xml use dom4j -->

    <dependency>

    <groupId>dom4j</groupId>

    <artifactId>dom4j</artifactId>

    </dependency>

    <!-- jstl标签 -->

    <dependency>

    <groupId>jstl</groupId>

    <artifactId>jstl</artifactId>

    </dependency>

    <dependency>

    <groupId>taglibs</groupId>

    <artifactId>standard</artifactId>

    </dependency>

    <dependency>

    <groupId>org.slf4j</groupId>

    <artifactId>slf4j-log4j12</artifactId>

    </dependency>

    <dependency>

    <groupId>log4j</groupId>

    <artifactId>log4j</artifactId>

    </dependency>

    <dependency>

    <groupId>org.slf4j</groupId>

    <artifactId>slf4j-api</artifactId>

    </dependency>

    <dependency>

    <groupId>javax.activation</groupId>

    <artifactId>activation</artifactId>

    </dependency>

    <dependency>

    <groupId>cglib</groupId>

    <artifactId>cglib</artifactId>

    </dependency>

    <dependency>

    <groupId>net.fckeditor</groupId>

    <artifactId>java-core</artifactId>

    </dependency>

    <dependency>

    <groupId>org.json</groupId>

    <artifactId>json</artifactId>

    </dependency>

    <!--page -->

    <dependency>

    <groupId>com.babasport</groupId>

    <artifactId>page</artifactId>

    </dependency>

    <!-- solrJ -->

    <dependency>

    <groupId>org.apache.solr</groupId>

    <artifactId>solr-solrj</artifactId>

    </dependency>

    <!-- jedis Java接口 -->

    <dependency>

    <groupId>redis.clients</groupId>

    <artifactId>jedis</artifactId>

    </dependency>

    <!-- FastDFS client -->

    <dependency>

    <groupId>fastdfs_client</groupId>

    <artifactId>fastdfs_client</artifactId>

    </dependency>

    <dependency>

    <groupId>org.jboss.netty</groupId>

    <artifactId>netty</artifactId>

    </dependency>

    <dependency>

    <groupId>com.alibaba</groupId>

    <artifactId>dubbo</artifactId>

    <exclusions>

    <exclusion>

    <artifactId>spring</artifactId>

    <groupId>org.springframework</groupId>

    </exclusion>

    </exclusions>

    </dependency>

    <dependency>

    <groupId>com.alibaba</groupId>

    <artifactId>fastjson</artifactId>

    </dependency>

    <!-- Zookeeper 用于分布式服务管理 -->

    <dependency>

    <groupId>org.apache.zookeeper</groupId>

    <artifactId>zookeeper</artifactId>

    </dependency>

    <dependency>

    <groupId>com.github.sgroschupf</groupId>

    <artifactId>zkclient</artifactId>

    </dependency>

    <!-- Zookeeper 用于分布式服务管理 end -->

    <!-- Active MQ 开始 -->

    <dependency>

    <groupId>org.apache.activemq</groupId>

    <artifactId>activemq-all</artifactId>

    </dependency>

    <dependency>

    <groupId>org.apache.activemq</groupId>

    <artifactId>activemq-pool</artifactId>

    </dependency>

    <!-- Active MQ 结束 -->

    </dependencies>

    整合Spring+Mybatis

    1.1 Web.xml

    配置Spring的监听器   上下文

    四个Service项目: product, buyer, cms, solr这四个项目

    <?xml version="1.0" encoding="UTF-8"?>

    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"

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

    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <context-param>

    <param-name>contextConfigLocation</param-name>

    <param-value>classpath:application-context.xml</param-value>

    </context-param>

    <listener>

    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

    </listener>

    </web-app>

    1.2 application-context.xml

    calsspath, 也就是src/main/resources

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

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

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

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

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

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

    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"

    xsi:schemaLocation="http://www.springframework.org/schema/beans

    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd

    http://www.springframework.org/schema/mvc

    http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd

    http://www.springframework.org/schema/context

    http://www.springframework.org/schema/context/spring-context-4.0.xsd

    http://www.springframework.org/schema/aop

    http://www.springframework.org/schema/aop/spring-aop-4.0.xsd

    http://www.springframework.org/schema/tx

    http://www.springframework.org/schema/tx/spring-tx-4.0.xsd

    http://www.springframework.org/schema/task

       http://www.springframework.org/schema/task/spring-task-4.0.xsd

    http://code.alibabatech.com/schema/dubbo        

    http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

    <!-- 引入当前目录/config目录下的所有xml文件 -->

    <import resource="config/*.xml"/>

    </beans>

    1.1 Jdbc.xml 配置数据源

    src/main/resources/config目录下

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

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

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

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

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

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

    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"

    xsi:schemaLocation="http://www.springframework.org/schema/beans

    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd

    http://www.springframework.org/schema/mvc

    http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd

    http://www.springframework.org/schema/context

    http://www.springframework.org/schema/context/spring-context-4.0.xsd

    http://www.springframework.org/schema/aop

    http://www.springframework.org/schema/aop/spring-aop-4.0.xsd

    http://www.springframework.org/schema/tx

    http://www.springframework.org/schema/tx/spring-tx-4.0.xsd

    http://www.springframework.org/schema/task

       http://www.springframework.org/schema/task/spring-task-4.0.xsd

    http://code.alibabatech.com/schema/dubbo        

    http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

    <!-- 引入资源文件 -->

    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">

    <property name="locations">

    <list>

    <value>classpath:jdbc.properties</value>

    </list>

    </property>

    </bean>

    <!-- 数据源 -->

    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">

    <property name="driverClassName" value="${driverClassName}" />

    <property name="url" value="${url}" />

    <property name="username" value="${username}" />

    <property name="password" value="${password}" />

    </bean>

    </beans>

    1.2 Jdbc.properties

    Jdbc.properties

    src/main/resources目录下

    driverClassName=com.mysql.jdbc.Driver

    url=jdbc:mysql://localhost:3306/babasport?characterEncoding=UTF-8

    username=root

    password=admin

    1.3 事务管理

    Trans.xml

    src/main/resources/config目录下

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

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

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

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

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

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

    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"

    xsi:schemaLocation="http://www.springframework.org/schema/beans

    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd

    http://www.springframework.org/schema/mvc

    http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd

    http://www.springframework.org/schema/context

    http://www.springframework.org/schema/context/spring-context-4.0.xsd

    http://www.springframework.org/schema/aop

    http://www.springframework.org/schema/aop/spring-aop-4.0.xsd

    http://www.springframework.org/schema/tx

    http://www.springframework.org/schema/tx/spring-tx-4.0.xsd

    http://www.springframework.org/schema/task

       http://www.springframework.org/schema/task/spring-task-4.0.xsd

    http://code.alibabatech.com/schema/dubbo        

    http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

    <!-- 配置事务管理器 -->

    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

    <property name="dataSource" ref="dataSource"></property>

    </bean>

    <!-- 配置事务注解驱动 -->

    <tx:annotation-driven transaction-manager="transactionManager"/>

    </beans>

    1.4 扫描

    anotation.xml

    src/main/resources/config目录下

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

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

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

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

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

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

    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"

    xsi:schemaLocation="http://www.springframework.org/schema/beans

    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd

    http://www.springframework.org/schema/mvc

    http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd

    http://www.springframework.org/schema/context

    http://www.springframework.org/schema/context/spring-context-4.0.xsd

    http://www.springframework.org/schema/aop

    http://www.springframework.org/schema/aop/spring-aop-4.0.xsd

    http://www.springframework.org/schema/tx

    http://www.springframework.org/schema/tx/spring-tx-4.0.xsd

    http://www.springframework.org/schema/task

       http://www.springframework.org/schema/task/spring-task-4.0.xsd

    http://code.alibabatech.com/schema/dubbo        

    http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

    <!-- 开启注解扫描 -->

    <context:component-scan base-package="cn.centran.core"/>

    </beans>

    1.5 Mybatis

    Mybatis.xml

    src/main/resources/config目录下

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

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

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

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

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

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

    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"

    xsi:schemaLocation="http://www.springframework.org/schema/beans

    http://www.springframework.org/schema/beans/spring-beans-4.0.xsd

    http://www.springframework.org/schema/mvc

    http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd

    http://www.springframework.org/schema/context

    http://www.springframework.org/schema/context/spring-context-4.0.xsd

    http://www.springframework.org/schema/aop

    http://www.springframework.org/schema/aop/spring-aop-4.0.xsd

    http://www.springframework.org/schema/tx

    http://www.springframework.org/schema/tx/spring-tx-4.0.xsd

    http://www.springframework.org/schema/task

       http://www.springframework.org/schema/task/spring-task-4.0.xsd

    http://code.alibabatech.com/schema/dubbo        

    http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

    <!-- 配置会话工厂 -->

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">

    <property name="dataSource" ref="dataSource"></property>

    <property name="configLocation" value="classpath:SqlMapConfig.xml"></property>

    </bean>

    <!-- 配置Mapper扫描 -->

    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">

    <property name="basePackage" value="cn.centran.core.dao"></property>

    </bean>

    </beans>

    1.6 Mybaits-config.xml

    sqlMapConfig.xml

    src/main/resources目录下

    <?xml version="1.0" encoding="UTF-8" ?>

    <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"

    "http://mybatis.org/dtd/mybatis-3-config.dtd">

    <configuration>

    </configuration>

    1.7 Log4j.properties

    Log4j.properties

    src/main/resources目录下

    # Global logging configuration

    log4j.rootLogger=DEBUG, stdout

    # Console output...

    log4j.appender.stdout=org.apache.log4j.ConsoleAppender

    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout

    log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n

    1.1 Mapper

    dao项目中

    <?xml version="1.0" encoding="UTF-8" ?>

    <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >

    <mapper namespace="cn.centran.core.dao.TbTestMapper" >

    <insert id="insertTest" parameterType="cn.centran.core.pojo.TbTest">

    insert into tb_test (name, birthday) values(#{name}, #{birthday})

    </insert>

    </mapper>

    1.1 测试类

    product项目中测试

    @RunWith(SpringJUnit4ClassRunner.class)

    @ContextConfiguration(locations={"classpath:application-context.xml"})

    public class TestTbTest {

    @Autowired

    private TbTestService testService;

    @Test

    public void testInsertTbTest() throws Exception{

    TbTest tb = new TbTest();

    tb.setName("张三1");

    tb.setBirthday(new Date());

    testService.insertTbTest(tb);

    }

    }

    测试事务

    2.1 Service实现类 接口

    Product项目中

    @RunWith(SpringJUnit4ClassRunner.class)

    @ContextConfiguration(locations={"classpath:application-context.xml"})

    public class TestProduct {

    @Autowired

    private ProductDao productDao;

    @Test

    public void testProduct() throws Exception {

    Product product = productDao.selectByPrimaryKey(1L);

    System.out.println("==============="+product);

    }

    }

    Interface项目中

    public interface TbTestService {

    public void insertTbTest(TbTest tbTest);

    }

    Product项目中

    @Service("tbTestServiceImpl")

    @Transactional

    public class TbTestServiceImpl implements TbTestService{

    @Autowired

    private TbTestMapper testMapper;

    @Override

    public void insertTbTest(TbTest tbTest) {

    testMapper.insertTest(tbTest);

    throw new RuntimeException();

    }

    }

    整合Springmvc

    前端控制器

    处理器映射器

    处理器适配器

    视图解释器

    babasport-console, login, portal项目

    3.1 Web.xml

    前端控制器

    <?xml version="1.0" encoding="UTF-8"?>

    <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"

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

    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <servlet>

    <servlet-name>springmvc</servlet-name>

    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

    <init-param>

    <param-name>contextConfigLocation</param-name>

    <param-value>classpath:springmvc.xml</param-value>

    </init-param>

    </servlet>

    <servlet-mapping>

    <servlet-name>springmvc</servlet-name>

    <!--

    *.action  拦截以.aciton结尾的

    / 所有都拦截 (不包括.jsp)

    /* 所有都拦截( 包括 .png, .jpg, .jsp, .js, .css等所有)

    -->

    <url-pattern>*.action</url-pattern>

    </servlet-mapping>

    <filter>

    <filter-name>encoding</filter-name>

    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>

    <init-param>

    <param-name>encoding</param-name>

    <param-value>UTF-8</param-value>

    </init-param>

    </filter>

    <filter-mapping>

    <filter-name>encoding</filter-name>

    <url-pattern>/*</url-pattern>

    </filter-mapping>

    </web-app>

    3.2 Springmvc-console.xml

    处理器映射器

    处理器适配器

    视图解释器

    Console项目中

    SpringMvc.xml

    src/main/resources目录下

    <?xml version="1.0" encoding="UTF-8"?>

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

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

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

    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo" xmlns:mvc="http://www.springframework.org/schema/mvc"

    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd

            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd

            http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd

            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">

    <!-- 配置@Controller扫描 -->

    <context:component-scan base-package="cn.centran.core.controller"/>

    <!-- 配合注解驱动 -->

    <mvc:annotation-driven/>

    <!-- 配置视图解析器 -->

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

    <property name="prefix" value="/WEB-INF/console/"></property>

    <property name="suffix" value=".jsp"></property>

    </bean>

    </beans>

  • 相关阅读:
    Ibatis 使用心得
    java.net.ConnectException: Connection timed out
    ZK 最少限度加载页面js文件
    JAVA 获取网页流
    ZK 页面间参数传递
    删除 TOMCAT 上次关闭遗留下来的 SESSION 缓存
    Java 异常java.lang.IllegalArgumentException: Illegal group reference
    ZK textbox Constraint验证
    zk textbox 更改字体大小及高度
    通过http管理solrcore
  • 原文地址:https://www.cnblogs.com/hopeful8859-1/p/6885723.html
Copyright © 2020-2023  润新知