SSM框架的配置信息
2019-07-15 本文已影响0人
波波大人2018
spring-context.xml
<?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:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:task="http://www.springframework.org/schema/task"
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/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd">
<context:annotation-config />
<task:annotation-driven />
<!-- 启动对@AspectJ注解的支持 。这个是用于支持日志-->
<aop:aspectj-autoproxy proxy-target-class="true" />
<context:component-scan base-package="com.game">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>
<context:property-placeholder location="classpath:*.properties" local-override="true" />
<import resource="spring-datasource-admin.xml" />
<import resource="spring-datasource-buyu.xml" />
<import resource="spring-datasource-slot.xml" />
<import resource="spring-shiro.xml" />
<!-- 保存变量到application范围.全局的变量 -->
<bean class="org.springframework.web.context.support.ServletContextAttributeExporter">
<property name="attributes">
<map>
<entry key="systemName" value="${system.name}" />
<entry key="systemVer" value="${system.ver}" />
<entry key="uploadFileDir" value="${upload.file.dir}" />
<entry key="uploadHttpURL" value="${upload.http.url}" />
<entry key="gameServerUrl" value="${gameserver.url}" />
<entry key="gameServerBanhaoUrl" value="${gameserver.banhao.url}" />
<entry key="gameRewardCfgserver" value="${gameRewardCfgserver.url}" />
<entry key="reloadUpServerUrl" value="${reloadUpServerUrl.url}" />
<entry key="redisUrl" value="${redisUrl.url}" />
</map>
</property>
</bean>
</beans>
spring-datasource-admin.xml
这里可以配置多个数据源
<?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:tx="http://www.springframework.org/schema/tx"
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">
<!-- dataSource -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
<property name="driverClassName" value="${datasource.driverClassName}" />
<!-- 基本属性 url、user、password -->
<property name="url" value="${datasource.url}" />
<property name="username" value="${datasource.username}" />
<property name="password" value="${datasource.password}" />
<property name="validationQuery" value="SELECT 1" />
<property name="testOnBorrow" value="true"/>
<!-- 配置初始化大小、最小、最大 -->
<property name="initialSize" value="${datasource.initialSize}" />
<property name="minIdle" value="${datasource.minIdle}" />
<property name="maxActive" value="${datasource.maxActive}" />
</bean>
<!-- 事务管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 开启事务注解驱动 -->
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />
<!-- mapper scanner -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.game.admin,com.game.common.page" />
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>
<!-- mybatis session factory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- 自动扫描Mybatis XML目录, 省掉mybatis-config.xml里的手工配置 -->
<property name="mapperLocations">
<array>
<value>classpath:com/game/admin/**/*.xml</value>
<value>classpath:com/game/common/**/*.xml</value>
</array>
</property>
</bean>
</beans>
spring-mvc.xml
<?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:mvc="http://www.springframework.org/schema/mvc"
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/schema/mvc/spring-mvc.xsd">
<mvc:annotation-driven>
<mvc:message-converters register-defaults="true">
<bean class="org.springframework.http.converter.StringHttpMessageConverter">
<constructor-arg value="UTF-8"></constructor-arg>
</bean>
</mvc:message-converters>
</mvc:annotation-driven>
<mvc:default-servlet-handler />
<mvc:resources mapping="/resources/**" location="/resources/" />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views" />
<property name="suffix" value=".jsp" />
</bean>
<!-- 扫描Controller,不扫描Service -->
<context:component-scan base-package="com.game">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" />
</context:component-scan>
<!-- 支持Shiro对Controller的方法级AOP安全控制 -->
<bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator" depends-on="lifecycleBeanPostProcessor">
<property name="proxyTargetClass" value="true" />
</bean>
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- 设置上传文件的最大尺寸,-1表示不限制大小,10M = 10485760 -->
<property name="maxUploadSize">
<value>10485760</value>
</property>
<!-- 最大内存大小 (10240) -->
<property name="maxInMemorySize">
<value>10240</value>
</property>
</bean>
</beans>
spring-shiro.xml 权限配置
<?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"
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">
<!-- 自定义Realm -->
<bean id="myRealm" class="com.game.shiro.ShiroAccountRealm">
<property name="credentialsMatcher" ref="credentialsMatcher"></property>
<property name="cachingEnabled" value="false" />
</bean>
<!-- 配置凭证算法匹配器 -->
<bean id="credentialsMatcher" class="org.apache.shiro.authc.credential.HashedCredentialsMatcher">
<property name="hashAlgorithmName" value="md5"></property> <!-- 加密算法的名称 -->
<property name="hashIterations" value="1"></property> <!-- 配置加密的次数 -->
</bean>
<!-- 配置权限管理器 -->
<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
<!-- ref对应我们写的realm -->
<property name="realm" ref="myRealm" />
</bean>
<!-- 配置shiro的过滤器工厂类,id- shiroFilter要和我们在web.xml中配置的过滤器一致 -->
<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
<!-- 调用我们配置的权限管理器 -->
<property name="securityManager" ref="securityManager" />
<!-- 配置我们的登录请求地址 -->
<property name="loginUrl" value="/" />
<!-- 配置我们在登录页登录成功后的跳转地址,如果你访问的是非/login地址,则跳到您访问的地址 -->
<property name="successUrl" value="/index" />
<!-- 如果您请求的资源不再您的权限范围,则跳转到/403请求地址 -->
<property name="unauthorizedUrl" value="/" />
<!-- 权限配置 -->
<property name="filterChainDefinitions">
<value>
/resources/** = anon
/ = anon
/gologin = anon
/upload = anon
/index = user
/logout = user
/changePwd/** = user
/** = user
</value>
</property>
</bean>
<!-- 保证实现了Shiro内部lifecycle函数的bean执行 -->
<bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" />
<!-- Shiro开启事务注解 -->
<bean class="org.apache.shiro.spring.security.interceptor.AuthorizationAttributeSourceAdvisor">
<property name="securityManager" ref="securityManager" />
</bean>
</beans>
datasource.properties数据源配置
# 可以配置多个数据源
datasource.driverClassName = com.mysql.jdbc.Driver
datasource.url = XXX?useUnicode=true&characterEncoding=utf8&autoReconnect=true&useSSL=false
datasource.username = XXX
datasource.password = XXX
datasource.initialSize = 3
datasource.minIdle = 5
datasource.maxActive = 50
config.properties
#这里的要和spring-context.xml 中的org.springframework.web.context.support.ServletContextAttributeExporter保持一致
system.name = \u6765\u6765\u6355\u9C7C
log4j日志
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<!-- Appenders -->
<appender name="console" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.out" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%p %d{yyyy-MM-dd HH:mm:ss,SSS} (%c:%L)- %m%n" />
</layout>
</appender>
<!-- Appenders -->
<appender name="file" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="/usr/local/tomcat/webapps/logs/buyu-admin/admin.log" />
<!-- <param name="File" value="src/main/webapp/image/admin.log" /> -->
<!-- 设置是否在重新启动服务时,在原有日志的基础添加新日志 -->
<param name="Append" value="true" />
<param name="MaxBackupIndex" value="100" />
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%p %d{yyyy-MM-dd HH:mm:ss,SSS} (%c:%L)- %m%n" />
</layout>
</appender>
<!-- Application Loggers -->
<!-- <logger name="com.game">
<level value="trace" />
</logger> -->
<logger name="org.springframework">
<level value="info" />
</logger>
<logger name="org.apache.commons">
<level value="info" />
</logger>
<!-- Root Logger 本地测试时需要改为console,正式服需要改为file-->
<root>
<priority value="debug" />
<appender-ref ref="console" />
</root>
</log4j:configuration>