项目通用配置xml
Posted wq-9
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了项目通用配置xml相关的知识,希望对你有一定的参考价值。
SqlMapperClient.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <!-- 配置分页插件 --> </configuration>
/src/main/resources/spring/applicationContext-dao.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:p="http://www.springframework.org/schema/p" 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/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- 配置解析properties文件的工具类 --> <context:property-placeholder location="classpath:resource/*.properties"/> <!-- 配置数据源 dataSource --> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" destroy-method="close"> <property name="url" value="$jdbc.url" /> <property name="username" value="$jdbc.username" /> <property name="password" value="$jdbc.password" /> <property name="driverClassName" value="$jdbc.driver" /> <property name="maxActive" value="10" /> <property name="minIdle" value="5" /> </bean> <!-- 创建mybatis的上下文对象 --> <bean class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource"> <ref bean="dataSource"/> </property> <property name="configLocation"> <value>classpath:mybatis/SqlMapperClient.xml</value> </property> </bean> <!-- 扫描mybatis的接口与映射配置文件 --> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.bjsxt.mapper"/> </bean> </beans>
/src/main/resources/spring/applicationContext-Jedis.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:p="http://www.springframework.org/schema/p" 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/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- jedisPool的配置 --> <bean id="poolconfig" class="redis.clients.jedis.JedisPoolConfig"> <!-- 最大连接数 --> <property name="maxTotal" value="30" /> <!-- 最大空闲连接数 --> <property name="maxIdle" value="10" /> <!-- 每次释放连接的最大数目 --> <property name="numTestsPerEvictionRun" value="1024" /> <!-- 释放连接的扫描间隔(毫秒) --> <property name="timeBetweenEvictionRunsMillis" value="30000" /> <!-- 连接最小空闲时间 --> <property name="minEvictableIdleTimeMillis" value="1800000" /> <!-- 连接空闲多久后释放, 当空闲时间>该值 且 空闲连接>最大空闲连接数 时直接释放 --> <property name="softMinEvictableIdleTimeMillis" value="10000" /> <!-- 获取连接时的最大等待毫秒数,小于零:阻塞不确定的时间,默认-1 --> <property name="maxWaitMillis" value="1500" /> <!-- 在获取连接的时候检查有效性, 默认false --> <property name="testOnBorrow" value="true" /> <!-- 在空闲时检查有效性, 默认false --> <property name="testWhileIdle" value="true" /> <!-- 连接耗尽时是否阻塞, false报异常,ture阻塞直到超时, 默认true --> <property name="blockWhenExhausted" value="false" /> </bean> <!-- 配置JedidesPool --> <bean id="jedisPool" class="redis.clients.jedis.JedisPool"> <constructor-arg name="poolConfig"> <ref bean="poolconfig"/> </constructor-arg> <constructor-arg name="host"> <value>192.168.70.145</value> </constructor-arg> <constructor-arg name="port"> <value>6379</value> </constructor-arg> </bean> <!-- JedisDaoImplSingle --> <bean id="jedisDaoImplSingle" class="com.bjsxt.jedisdao.impl.JedisDaoImplSingle"></bean> <!-- JedislCluster --> <bean id="jedisCluster" class="redis.clients.jedis.JedisCluster"> <constructor-arg name="nodes"> <set> <bean class="redis.clients.jedis.HostAndPort"> <constructor-arg name="host"> <value>192.168.70.145</value> </constructor-arg> <constructor-arg name="port"> <value>8001</value> </constructor-arg> </bean> <bean class="redis.clients.jedis.HostAndPort"> <constructor-arg name="host"> <value>192.168.70.145</value> </constructor-arg> <constructor-arg name="port"> <value>8002</value> </constructor-arg> </bean> <bean class="redis.clients.jedis.HostAndPort"> <constructor-arg name="host"> <value>192.168.70.145</value> </constructor-arg> <constructor-arg name="port"> <value>8003</value> </constructor-arg> </bean> <bean class="redis.clients.jedis.HostAndPort"> <constructor-arg name="host"> <value>192.168.70.145</value> </constructor-arg> <constructor-arg name="port"> <value>8004</value> </constructor-arg> </bean> <bean class="redis.clients.jedis.HostAndPort"> <constructor-arg name="host"> <value>192.168.70.145</value> </constructor-arg> <constructor-arg name="port"> <value>8005</value> </constructor-arg> </bean> <bean class="redis.clients.jedis.HostAndPort"> <constructor-arg name="host"> <value>192.168.70.145</value> </constructor-arg> <constructor-arg name="port"> <value>8006</value> </constructor-arg> </bean> </set> </constructor-arg> <constructor-arg name="poolConfig"> <ref bean="poolconfig"/> </constructor-arg> </bean> <!-- JedisDaoImplCluster --> <!-- <bean id="jedisDaoImplCluster" class="com.bjsxt.jedisdao.impl.JedisDaoImplCluster"></bean> --> </beans>
/src/main/resources/spring/applicationContext-service.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:p="http://www.springframework.org/schema/p" 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/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- 扫描bean对象 --> <context:component-scan base-package="com.bjsxt.service,com.bjsxt.jedisdao"/> </beans>
/src/main/resources/spring/applicationContext-trans.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:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" 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-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"> <!-- 配置事物管理器的切面 --> <bean id="transactionMananger" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"/> </bean> <!-- 配置事物传播行为 :其实就是那些方法应该受什么样的事物控制--> <tx:advice id="advice" transaction-manager="transactionMananger"> <tx:attributes> <tx:method name="add*" propagation="REQUIRED"/> <tx:method name="modify*" propagation="REQUIRED"/> <tx:method name="update*" propagation="REQUIRED"/> <tx:method name="dorp*" propagation="REQUIRED"/> <tx:method name="del*" propagation="REQUIRED"/> <tx:method name="find*" read-only="true"/> </tx:attributes> </tx:advice> <!-- 那些类下的方法需要参与到当前的事物管理中 。配置切点 --> <aop:config> <aop:advisor advice-ref="advice" pointcut="execution(* com.bjsxt.service.*.*(..))"/> </aop:config> </beans>
springmvc.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:p="http://www.springframework.org/schema/p" 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/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!-- 包的扫描器主要是扫描@controller --> <context:component-scan base-package="com.bjsxt.web.controller"/> <!-- 注册两个新对象 主要是为了来处理springmvc中的其他anntation 如:@requestmapping --> <mvc:annotation-driven/> <!-- 视图解析器 --> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/jsp/" /><!-- jsp所在的前缀 --> <property name="suffix" value=".jsp" /> </bean> <!-- 配置静态资源映射 --> <mvc:resources location="/WEB-INF/css/" mapping="/css/**"/> <mvc:resources location="/WEB-INF/js/" mapping="/js/**"/> </beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <!-- 上下文参数,告诉Spring配置文件路径 --> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/applicationContext-*.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- 配置springmvc --> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/springmvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <filter> <filter-name>encoding</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>encoding</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> </web-app>
以上是关于项目通用配置xml的主要内容,如果未能解决你的问题,请参考以下文章
Android 屏幕适配屏幕适配通用解决方案 ① ( 定义 dimens.xml 方案 | 使用 ScreenMatch 插件生成不同屏幕分辨率的 dimens.xml 配置 )
Android 屏幕适配屏幕适配通用解决方案 ① ( 定义 dimens.xml 方案 | 使用 ScreenMatch 插件生成不同屏幕分辨率的 dimens.xml 配置 )