配置文件总结

永久解决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.itcast.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.itcast.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.itcast.core.dao.TbTestMapper" >

<insert id="insertTest" parameterType="cn.itcast.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.itcast.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>

时间: 2024-10-19 02:15:09

配置文件总结的相关文章

linux下Nginx配置文件(nginx.conf)配置设置详解(windows用phpstudy集成)

linux备份nginx.conf文件举例: cp /usr/local/nginx/nginx.conf /usr/local/nginx/nginx.conf-20171111(日期) 在进程列表里 面找master进程,它的编号就是主进程号. ps -ef | grep nginx 查看进程 cat /usr/local/nginx/nginx.pid 每次修改完nginx文件都要重新加载配置文件linux命令: /usr/local/nginx -t //验证配置文件是否合法 若ngin

nginx配置文件详解

nginx配置文件nginx.conf超详细讲解 #nginx进程,一般设置为和cpu核数一样worker_processes 4;                        #错误日志存放目录 error_log  /data1/logs/error.log  crit;  #运行用户,默认即是nginx,可不设置user nginx       #进程pid存放位置pid        /application/nginx/nginx.pid; #Specifies the value

环境变量配置文件

让配置文件立即生效:source 配置文件 或 . 配置文件 /etc/profile 例:定义了HISTSIZE=1000 /etc/profile.d/*.sh /etc/bashrc ~/.bash_profile 例:定义了PATH=$PATH:$HOME/bin ~/.bashrc 例:定义了当前用户的命令别名 ~/.bash_history 注释:历史命令

Linux中的环境变量配置文件及其作用

登录相关的配置文件: /etc/profile 范围:对所有用户生效 作用: a.定义USER变量 b.定义LOGNAME变量 c.定义MAIL变量 d.定义PATH变量 e.定义HOSTNAME变量 f.定义HISTSIZE变量 g.定义umask值 i.调用/etc/profile.d/*.sh文件 /etc/profile.d/*.sh 范围:对所有用户生效 说明:这是一族sh文件,没个都会被调用 例如: /etc/profile.d/lang.sh 作用:调用/etc/sysconfg/

spring配置文件详解

转自: http://book.51cto.com/art/201004/193743.htm 此处详细的为我们讲解了spring2.5的实现原理,感觉非常有用 spring配置文件是用于指导Spring工厂进行Bean生产.依赖关系注入(装配)及Bean实例分发的"图纸".JavaEE程序员必须学会并灵活应用这份"图纸"准确地表达自己的"生产意图".Spring配置文件是一个或多个标准的XML文档,applicationContext.xml是

Hyper-V虚拟机Redhat添加网卡找不到网卡配置文件解决方法

环境:Hyper-V虚拟机上面安安装Redhat6.7 问题:系统安装时,只有一块网卡,现根据需要,增加一块网卡,DHCP获取IP地址,在Hyper-V设置中增加网卡后,存在连个问题:1./etc/sysconfig/network-scripts/中找不到配置文件且无法连接外网 解决方法: 1.cat /etc/udev/rules.d/70-persistent-net.rules 查看网卡的MAC地址和网卡名称 2. 在/etc/sysconfig/network-scripts/下建立i

004-用户、组、权限管理命令及bash配置文件、管道、重定向、grep

l  1.用户管理命令 1.)创建用户命令 useradd  [OPTIONS] USERNAME -u(UID):指定用户UID -g(GID):指定基本组 -G( group,...):指定附加组 -c"COMMENT":指定注释信息 -d(home_dir):指定家目录/path/to/directory -s:指定SHELL路径(/etc/shells指定了当前系统可用的安全shell) -m –k:强行为用户创建家目录 -M:不创建用户家目录 /etc/login.defs

PHP配置文件经典漏洞

phithon师父在小蜜圈里放了一个经典的配置文件写入问题漏洞. <?phpif(!isset($_GET['option'])) die();$str = addslashes($_GET['option']);$file = file_get_contents('./config.php');$file = preg_replace('|\$option=\'.*\';|', "\$option='$str';", $file);file_put_contents('./co

CentOS 7以yum方式安装zabbix3.2及配置文件详解

一.zabbix简介与环境准备 简介详见 ---> zabbix简介 环境准备: CentOS 7(node7):zabbix-server,web,mysql,agent mariadb:5.5.50 zabbix组件:3.2.1 apache:2.4.6 二.安装与配置 1.安装数据库(mariadb),可直接yum安装 [[email protected] ~]# vim /etc/yum.repos.d/MariaDB.repo [mariadb]  name = MariaDB  ba

python:配置文件configparser

#-*- coding:utf8 -*- # Auth:fulimei import configparser #第一个标签 conf=configparser.ConfigParser() conf['DEFAULT']={'ServerAliveInterval': '45', 'Compression': 'yes', 'CompressionLevel': '9'} conf['DEFAULT']['ForwardX11'] = 'yes' #第二个标签 conf['bitbucket.