版本一

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.2.xsd "> <!--1 读取database.properties文件 -->
<context:property-placeholder location="classpath:database.properties"/> <!--2 准备druid连接池 -->
<bean name="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="driverClassName" value="${jdbc.driverClass}"></property>
<property name="url" value="${jdbc.jdbcUrl}"></property>
<property name="username" value="${jdbc.user}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean> <!-- c3p0连接池 -->
<!-- <bean name="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driverClass}"></property>
<property name="jdbcurl" value="${jdbc.jdbcUrl}"></property>
<property name="user" value="${jdbc.user}"></property>
<property name="password" value="${jdbc.password}"></property>
</bean> --> <!--3 将SessionFactory配置到spring容器中 -->
<!-- 加载配置方案1:仍然使用外部的hibernate.cfg.xml配置信息 -->
<!-- <bean name="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
</bean> --> <!-- 加载配置方案2:在spring配置中放置hibernate配置信息 -->
<bean name="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<!-- 将连接池注入到sessionFactory, hibernate会通过连接池获得连接 -->
<property name="dataSource" ref="dataSource"></property>
<!-- 配置hibernate基本信息 -->
<property name="hibernateProperties">
<props>
<!-- 必选配置 -->
<!-- <prop key="hibernate.connection.driver_class">com.mysql.jdbc.Driver</prop>
<prop key="hibernate.connection.url">jdbc:mysql:///hibernate</prop>
<prop key="hibernate.connection.username">root</prop>
<prop key="hibernate.connection.password">root</prop> -->
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop> <!-- 可选配置 -->
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
<!-- 引入orm元数据,指定orm元数据所在的包路径,spring会自动读取包中的所有配置 -->
<property name="mappingDirectoryLocations" value="classpath:www/test/domain"></property> <!-- 使用maven工厂的时候因为domain会打包成一个jar配置目录就不好使了,需要使用下面的配置 -->
<!-- <property name="mappingLocations">
<list>
<value>classpath:www/test/domain/*.xml</value>
</list>
</property> --> </bean> <!--4 核心事务管理器 依赖于SessionFactory-->
<bean name="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean> <!--5 配置通知 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="save*" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="false"/>
<tx:method name="persist*" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="false"/>
<tx:method name="update*" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="false"/>
<tx:method name="modify*" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="false"/>
<tx:method name="delete*" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="false"/>
<tx:method name="remove*" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="false"/>
<tx:method name="find*" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="true"/>
<tx:method name="get*" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="true"/>
<tx:method name="*" isolation="REPEATABLE_READ" propagation="REQUIRED" read-only="false"/>
</tx:attributes>
</tx:advice> <!--6 配置将通知织入目标对象 配置切点+配置切面 -->
<aop:config>
<aop:pointcut expression="execution(* www.test.service.impl.*ServiceImpl.*(..))" id="txPc"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPc"/>
</aop:config> <!--7 action -->
<bean name="userAction" class="www.test.web.action.UserAction" scope="prototype">
<property name="us" ref="userService"></property>
</bean>
<bean name="customerAction" class="www.test.web.action.CustomerAction" scope="prototype">
<property name="cs" ref="customerService"></property>
</bean>
<bean name="baseDictAction" class="www.test.web.action.BaseDictAction" scope="prototype">
<property name="baseDictService" ref="baseDictService"></property>
</bean>
<bean name="linkManAction" class="www.test.web.action.LinkManAction" scope="prototype">
<property name="lms" ref="linkManService"></property>
<property name="cs" ref="customerService"></property>
</bean>
<bean name="saleVisitAction" class="www.test.web.action.SaleVisitAction" scope="prototype">
<property name="svs" ref="saleVisitService"></property>
</bean> <!--8 service -->
<bean name="userService" class="www.test.service.impl.UserServiceImpl">
<property name="ud" ref="userDao"></property>
</bean>
<bean name="customerService" class="www.test.service.impl.CustomerServiceImpl">
<property name="cd" ref="customerDao"></property>
</bean>
<bean name="baseDictService" class="www.test.service.impl.BaseDictServiceImpl">
<property name="baseDictDao" ref="baseDictDao"></property>
</bean>
<bean name="linkManService" class="www.test.service.impl.LinkManServiceImpl">
<property name="lmd" ref="linkManDao"></property>
</bean>
<bean name="saleVisitService" class="www.test.service.impl.SaleVisitServiceImpl">
<property name="svd" ref="saleVisitDao"></property>
</bean> <!--9 dao -->
<bean name="userDao" class="www.test.dao.impl.UserDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean name="customerDao" class="www.test.dao.impl.CustomerDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean name="baseDictDao" class="www.test.dao.impl.BaseDictDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean name="linkManDao" class="www.test.dao.impl.LinkManDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<bean name="saleVisitDao" class="www.test.dao.impl.SaleVisitDaoImpl">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean> </beans>

版本二 bos

<?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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:soap="http://cxf.apache.org/bindings/soap"
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/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://cxf.apache.org/bindings/soap
http://cxf.apache.org/schemas/configuration/soap.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd
"> <!-- 1 加载属性文件 -->
<context:property-placeholder location="classpath:db.properties"/> <!-- 2 配置数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="driverClass" value="${jdbc.driverClass}"/>
<property name="jdbcUrl" value="${jdbc.jdbcUrl}"/>
<property name="user" value="${jdbc.user}"/>
<property name="password" value="${jdbc.password}"/>
</bean> <!--3 配置LocalSessionFactoryBean,spring提供的用于整合hibernate的工厂bean -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<!-- 注入hibernate相关的属性配置 -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
<!-- 注入hibernate的映射文件 -->
<property name="mappingLocations">
<list>
<value>classpath:com/test/bos/domain/*.xml</value>
</list>
</property>
<!--这种方式注入hibernate的映射文件在maven开发中是不可以的,domain是要打成jar包的 -->
<!-- <property name="mappingDirectoryLocations" value="classpath:www/test/domain"></property> --> </bean> <!-- 4 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean> <!-- 5 组件扫描 -->
<context:component-scan base-package="com.test.bos"/> <!-- 6 支持spring注解 -->
<context:annotation-config /> <!-- 7 注解事务 -->
<tx:annotation-driven/> <!-- 注册crm客户端代理对象 -->
<jaxws:client id="crmClient"
address="http://localhost:8080/bos-crm/service/customer"
serviceClass="com.test.bos.utils.cxf.ICustomerService">
</jaxws:client> <!--配置shiro框架的过滤器工厂对象 -->
<bean name="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<property name="securityManager" ref="securityManager"></property>
<property name="loginUrl" value="/login.jsp"></property>
<property name="successUrl" value="/index.jsp"></property>
<property name="unauthorizedUrl" value="/unauthorized.jsp"></property>
<!-- 指定url级别的拦截策略 -->
<property name="filterChainDefinitions">
<value>
/css/** = anon
/js/** = anon
/images/** = anon
/login.jsp* = anon
/validatecode.jsp* = anon
/UserAction_login.action = anon
/page_base_staff.action = perms["staff"]
/* = authc
</value>
</property>
</bean> <!-- 注册安全管理器对象 -->
<bean name="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<property name="realm" ref="bosRealm"></property>
<!--注入缓存管理器 -->
<property name="cacheManager" ref="cacheManager"></property>
</bean> <!--注册缓存管理器 -->
<bean name="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
<!-- 注册ehcache的配置文件 -->
<property name="cacheManagerConfigFile" value="classpath:ehcache.xml"></property>
</bean> <!-- 注册自定义realm -->
<bean name="bosRealm" class="com.test.bos.service.realm.BOSRealm"></bean> <!--
<property name="proxyTargetClass" value="false"/>其中 value="false"
会出现 NoSuchMethodException: com.sun.proxy.$Proxy86.pageQuery 异常, 为 false 的时候, 使用的 jdk 代理,
JDK 代理也就是实现一个接口, 实现的 ModelDriven<T>接口。 间接实现的, 因为 StaffAction 继承了
BaseAction,BaseAction 又实现了 ModelDriven 接口, 而 ModelDriven 里面只有一个 getModel 方法, 根本没有
pageQuery 方法。 所以必须使用 cglib 代理方式。 因为使用 cglib 创建代理会继承 StaffAction,所以就肯定能有
pageQuery 方法。 所以这里需要强制使用 cglib 代理。
-->
<!--开启 shiro 框架注解支持-->
<bean name="defaultAdvisorAutoProxyCreator"
class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator">
<!-- 必须使用 cglib 方式为 Action 对象创建代理对象 -->
<property name="proxyTargetClass" value="true"></property>
</bean> <!-- 配置 shiro 框架提供的切面类, 用于创建代理对象 -->
<bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor"></bean> <!-- quartz配置-1 注册自定义作业类 -->
<bean name="myJob" class="com.test.jobs.MailJob">
<property name="username" value="luojun281@126.com"/>
<property name="password" value="123456ljp"/>
<property name="smtpServer" value="smtp.126.com"/>
<property name="protocol" value="SMTP"/>
</bean> <!-- quartz配置-2 配置JobDetail -->
<bean name="myJobDetail"
class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<!-- 注入目标对象 -->
<property name="targetObject" ref="myJob"></property>
<!-- 注入目标方法 -->
<property name="targetMethod" value="execute"></property>
</bean> <!--quartz配置-3 配置触发器Trigger -->
<bean name="myTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<!-- 注入任务详情对象 -->
<property name="jobDetail" ref="myJobDetail"></property>
<!-- 注入cron表达式,通过这个表达式指定触发的时间点 -->
<property name="cronExpression">
<!-- 每过两分钟发送一次 -->
<value>0 0/2 * * * ? 2020-2099</value>
</property>
</bean>
<!--quartz配置-4 配置scheduler调度工厂-->
<bean name="schedulerFactory" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<!-- 注入触发器 -->
<property name="triggers">
<list>
<ref bean="myTrigger"/>
</list>
</property>
</bean>
</beans>

版本三 Mybatis-Spring

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://www.springframework.org/schema/beans"
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:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-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/util
http://www.springframework.org/schema/util/spring-util-4.0.xsd"> <!-- 1加载配置文件 -->
<context:property-placeholder location="classpath:db.properties" /> <!-- 2配置连接池 -->
<bean name="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driver}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
<property name="maxActive" value="10" />
<property name="maxIdle" value="5" />
</bean> <!--3 配置SqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!-- 配置mybatis核心配置文件 -->
<property name="configLocation" value="classpath:SqlMapConfig.xml" />
<!-- 配置数据源 -->
<property name="dataSource" ref="dataSource" />
</bean> <!-- 原始开发方式中,配置dao到spring中 -->
<bean name="userDao" class="com.mybatis.spring.dao.impl.UserDaoImpl">
<!-- 注入SqlSessionFatory -->
<property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
</bean> <!-- Mapper代理的方式开发方式一,配置Mapper代理对象 -->
<bean name="userMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
<!-- 配置mapper接口 -->
<property name="mapperInterface" value="com.mybatis.spring.mapper.IUserMapper"></property>
<!-- 配置sqlSessionFactory -->
<property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
</bean> <!-- Mapper代理的方式开发方式二,扫描包方式配置代理
每个mapper代理对象的id就是类名,首字母小写。
om.mybatis.spring.mapper下面就算还有子包,也会扫描到的。
-->
<!--
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.mybatis.spring.mapper"></property>
</bean>
-->
</beans>

028-applicationContext.xml配置文件的更多相关文章

  1. Spring中,applicationContext.xml 配置文件在web.xml中的配置详解

    一.首先写一下代码结构. 二.再看web.xml中的配置情况. <?xml version="1.0" encoding="UTF-8"?> < ...

  2. 在web.xml注册applicationContext.xml配置文件

    概要: Spring配置文件是集成了Spring框架的项目的核心,引擎的开始是:容器先是加载web.xml,接着是applicationContext.xml在web.xml里的注册.以下我们将介绍a ...

  3. [JavaEE] applicationContext.xml配置文件使用合集

    配置实例 – 1 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http ...

  4. applicationContext.xml 配置文件的存放位置

    eb.xml中classpath:和classpath*:  有什么区别? classpath:只会到你的class路径中查找找文件; classpath*:不仅包含class路径,还包括jar文件中 ...

  5. 模拟Spring中applicationContext.xml配置文件初始化bean的过程

    package com.xiaohao.action; import java.io.File; import java.lang.reflect.Method; import java.util.C ...

  6. spring applicationContext.xml 配置文件 详解

      <?xml version="1.0" encoding="UTF-8"?>   <beans xmlns="http://ww ...

  7. 关于spring的applicationContext.xml配置文件的ref和value之自我想法

    今天在做SSH的一个项目的时候,因为需要定时操作,所以就再sping里面加入了一个quartz的小定时框架,结果在运行时候,发生了一个小bug. Caused by: org.springframew ...

  8. STS中applicationContext.xml配置文件

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  9. Spring 框架的 applicationContext.xml 配置文件

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  10. zookeeper中controller项目中资源配置文件applicationContext.xml配置文件编写

    <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.spr ...

随机推荐

  1. hbase项目

    四.HBase 项目4.1.涉及概念梳理:命名空间4.1.1.命名空间的结构 1) Table:表,所有的表都是命名空间的成员,即表必属于某个命名空间,如果没有指定, 则在 default 默认的命名 ...

  2. 洛谷P1501 [国家集训队]Tree II(打标记lct)

    题目描述 一棵n个点的树,每个点的初始权值为1.对于这棵树有q个操作,每个操作为以下四种操作之一: + u v c:将u到v的路径上的点的权值都加上自然数c: - u1 v1 u2 v2:将树中原有的 ...

  3. ASP.NET mvc4 Controllder 同步还是异步

    从抽象类Controller 的定义可以看出他 同时实现了 IAsyncController, IController public abstract class Controller : Contr ...

  4. [LeetCode 题解]:Combinations

    Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For exampl ...

  5. python下使用tesserocr遇到的一些坑

    我是在win7 64位系统下用的. 首先是安装tesseract,这个可以去官网下载,我使用的是3.05.1,安装时使用默认安装路径就行了,下载语言包速度很慢很慢,需要等 接下来就是安装tessero ...

  6. SQL Server 2012 表分区

    转载于:https://www.cnblogs.com/knowledgesea/p/3696912.html 什么是表分区 一般建立数据库表时,表数据都存放在一个文件里. 但是如果是分区表的话,表数 ...

  7. 中文 bootstrapValidator

    官网地址:http://bassistance.de/jquery-plugins/jquery-plugin-validation jQuery plugin: Validation 使用说明 转载 ...

  8. codis__数据迁移和伸缩容

    数据迁移命令 注意点:是迁移到某个 redis-group 而不是某个redis-servers  实例 伸缩容用法 redis 内存等不够用时 增容 : 增加redis-group, 然后迁移使用上 ...

  9. 浅谈Android选项卡(一)

    选项卡,这样UI设计在很多方面都存在,window,web,ios,Android. 选项卡的主要作用,不用多介绍,可以在有线的空间内,显示出更多内容,同时也是操作起来也很方便.

  10. virsh 连接虚拟机 (vnc 或 控制台)

    第一种方式 1.如果虚拟机登录方式为VNC,在ubuntu机器上安装vncviewer 在虚拟机的配置xml中 <graphics type="vnc" autoport=& ...