黑马程序员技术交流社区
标题:
【成都校区】
[打印本页]
作者:
yrt224
时间:
2019-6-6 15:06
标题:
【成都校区】
hibernate持久层配置,shiro安全框架,ecache缓存和任务调度的配置
<?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
">
<!-- 加载属性文件 -->
<context:property-placeholder location="classpath:db.properties"/>
<!-- 配置数据源 -->
<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>
<!-- 配置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/itheima/bos/domain/*.xml</value>
</list>
</property>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<!-- 组件扫描 -->
<context:component-scan base-package="com.itheima.bos"/>
<!-- 支持spring注解 -->
<context:annotation-config/>
<!-- 支持事务注解 -->
<tx:annotation-driven/>
<!-- 注册crm客户端代理对象 -->
<jaxws:client id="crmClient"
serviceClass="cn.heima.crm.service.CustomerService"
address="http://localhost:8080/crm_webservice/service/customer"/>
<!-- 配置shiro框架的过滤器工厂对象-->
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<!-- 注入安全管理器对象-->
<property name="securityManager" ref="securityManager"></property>
<!-- 注入相关页面访问url-->
<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
/validatecode.jsp*=anon
/login.jsp=anon
/userAction_login.action=anon
/page_base_staff.action=perms["staff.list"]
/*=authc
</value>
</property>
</bean>
<!-- 注册安全管理器对象-->
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<property name="realm" ref="bosRealm"></property>
<!-- 注入缓存管理器-->
<property name="cacheManager" ref="cacheManager"></property>
</bean>
<!-- 注册缓存管理器 -->
<bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
<!-- 注入ehcache的配置文件 -->
<property name="cacheManagerConfigFile" value="classpath:ehcache.xml"/>
</bean>
<!-- 注册Realm-->
<bean id="bosRealm" class="com.itheima.bos.realm.BosRealm"></bean>
<!-- 开启shiro注解支持-->
<bean id="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>
<!-- 配置自定义邮件作业对象,注入发件人用户名,密码,服务地址-->
<!-- 注册自定义作业类-->
<bean id="mailJob" class="com.itheima.bos.job.MailJob">
<property name="username" value="962202481@qq.com"></property>
<property name="password" value="sdlkvfpicjpxbbch"></property>
<property name="smtpServer" value="smtp.qq.com"></property>
</bean>
<!-- 配置作业详情JobDetail-->
<bean id="jobDetail" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<!-- 注入目标对象 -->
<property name="targetObject" ref="mailJob"></property>
<!-- 注入目标方法-->
<property name="targetMethod" value="execute"></property>
</bean>
<!-- 配置触发器-->
<bean id="mailTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<!-- 注入任务详情对象-->
<property name="jobDetail" ref="jobDetail"></property>
<!-- 注入层cron表达式-->
<property name="cronExpression">
<value>0 12 22 22 8 ? *</value>
</property>
</bean>
<!-- 配置调度工厂-->
<bean id="schedulerFactoryBeanS" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<!-- 注入触发器-->
<property name="triggers">
<list>
<ref bean="mailTrigger"/>
</list>
</property>
</bean>
</beans>
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2