applicationContext.xml

时光毁灭记忆、已成空白 提交于 2020-04-06 19:09:44

<?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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
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/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
">

<!-- 配置数据 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="url" value="jdbc:mysql://localhost:3306/db_blog?useSSL=false&amp;useUnicode=true&amp;characterEncoding=UTF8&amp;serverTimezone=GMT&amp;ampallowPublicKeyRetrieval=true"/>
<property name="username" value="root"/>
<property name="password" value="admin"/>
</bean>
<!--配置MyBatis的sqlSessionF -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<!--自动扫描mapper.xml文件 -->
<property name="mapperLocations" value="classpath:com/blog/mappers/*.xml"></property>
<!--MyBatis配置文件 -->
<property name="configLocation" value="classpath:mybatisConfig.xml"></property>
</bean>
<!-- DAO接口所在的包名,spring会自动扫描这个包下面的类 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.blog.dao"></property>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>
<!-- 事务管理 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>







<!--自定义Realm -->
<bean id="myRealm" class="com.blog.realm.MyRealm"></bean>

<!-- 安全管理器 -->
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager" >
<property name="realm" ref="myRealm"></property>
</bean>

<!--Shiro过滤器 -->
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<!--Shiro的核心安全接口,这个属性是必须的 -->
<property name="securityManager" ref="securityManager"></property>
<!--身份认证失败,挑战到登录页面的配置 -->
<property name="loginUrl" value="/login.jsp"></property>
<property name="filterChainDefinitions">
<value>
/login=anon
/admin/**=authc
</value>
</property>
</bean>

<!--保证实现了Shiro内部lifecycle函数的bean执行 -->
<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor"></bean>

<!-- 开启Shiro注解 -->
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor"></bean>

<bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
<property name="securityManager" ref="securityManager"></property>
</bean>








<tx:advice id="txAdvice" transaction-manager="transactionManager">
<!-- 定义事务的传播属性 -->
<tx:attributes>
<tx:method name="insert*" propagation="REQUIRED"></tx:method>
<tx:method name="update*" propagation="REQUIRED"></tx:method>
<tx:method name="edit*" propagation="REQUIRED"></tx:method>
<tx:method name="save*" propagation="REQUIRED"></tx:method>
<tx:method name="add*" propagation="REQUIRED"></tx:method>
<tx:method name="set*" propagation="REQUIRED"></tx:method>
<tx:method name="remove*" propagation="REQUIRED" ></tx:method>
<tx:method name="get*" propagation="REQUIRED" read-only="true"></tx:method>
<tx:method name="find*" propagation="REQUIRED" read-only="true"></tx:method>
<tx:method name="load*" propagation="REQUIRED" read-only="true"></tx:method>
<!-- <tx:method name="*" propagation="REQUIRED" read-only="true"></tx:method> -->
</tx:attributes>
</tx:advice>

<!--配置事务切面 -->
<aop:config>
<aop:pointcut expression="execution(* com.blog.service.*.*(..))" id="serviceOperation"></aop:pointcut>
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation"></aop:advisor>
</aop:config>

<!--自动扫描 -->
<context:component-scan base-package="com.blog.service"></context:component-scan>

</beans>

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!