一共是7个配置文件:下次给大家分享他们的关系配置属性
1.Spring.XML
2.SpringMVC.XML
3.Spring-Shiro.XML
4.Spring-Email.XML
5.Spring-quartz.XML
6.Web-Xml
7.pom-XML
1。Spring.XML的配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
<!-- 扫描包
@Controller @Service @Repository @Component
-->
<context:component-scan base-package="cn.itsource.service"/>
<context:component-scan base-package="cn.itsource.easypoi"/>
<!-- 开启Spring的注解支持 -->
<context:annotation-config/>
<!--
1)配置数据库连接池
dbcp.properties
2)配置JPA的EntityManagerFactory,使用FactoryBean的方式配置
3)支持全注解的事务管理 在Service层的实现类或者方法上面添加@Transactional注解即可
-->
<!--引入dbcp.properties文件-->
<context:property-placeholder location="classpath:dbcp.properties"/>
<!--配置dbcp连接池-->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<!--通常情况下以下四个key都要加前缀-->
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<!--配置JPA的EntityManagerFactory【FactoryBean方式配置】-->
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<!--引用一个数据库连接池-->
<property name="dataSource" ref="dataSource"/>
<!--指定我们的domain实体类【加了@Entity注解的实体类】在哪个包-->
<property name="packagesToScan" value="cn.itsource.domain"/>
<!--指定一个适配器-->
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<!--配置方言-->
<property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect"/>
<!--建表策略-->
<property name="generateDdl" value="false"/>
<!--是否显示SQL-->
<property name="showSql" value="true"/>
</bean>
</property>
</bean>
<!-- Service层添加事务管理【全注解添加事务管理】 -->
<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<!--
开启注解直接AOP
tx:annotation-driven 表示开启注解支持Spring的事务管理【AOP】,会查找默认的bean名称:transactionManager
transaction-manager属性可以指定事务管理器的bean名称,如果不指定默认找transactionManager
-->
<tx:annotation-driven transaction-manager="txManager" />
<!-- Spring Data Jpa配置 ********************************************-->
<!-- base-package:扫描的包 -->
<jpa:repositories base-package="cn.itsource.dao"
transaction-manager-ref="txManager" />
<!--
以下是集成SpringDataJPA的配置
base-package 表示指定一个包名,因为SpringDataJPA的DAO层只需要写接口,不需要写实现类【牛逼得很】
因为没有实现类,有需要创建对象,所以SpringDataJPA自动帮我们生成一个实现类,
所以扫描包就不能再使用context:component-scan扫描了,因为没有实现类,不能添加@Repository注解
factory-class="cn.itsource.factorybean.MyRepositoryFactoryBean"
SpringDataJPA默认使用SimpleJPARepository类作为自动生成的类的父类,如果需要修改就必须设置factory-class属性
-->
<jpa:repositories base-package="cn.itsource.dao" transaction-manager-ref="txManager"
factory-class="cn.itsource.factorybean.MyRepositoryFactoryBean" />
<!-- 引入spring-shiro.xml -->
<import resource="classpath:spring-shiro.xml"/>
</beans>
2。 SpringMVC.XML的配置
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/sch