Skip to content

Instantly share code, notes, and snippets.

@zhanzhenchao
Last active June 2, 2020 07:41
Show Gist options
  • Save zhanzhenchao/254a0f0f2fb2804268da to your computer and use it in GitHub Desktop.
Save zhanzhenchao/254a0f0f2fb2804268da to your computer and use it in GitHub Desktop.
spring
<?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:jee="http://www.springframework.org/schema/jee"
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.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<!--引入其他配置文件的配置参数-->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:/vino.properties</value>
</list>
</property>
</bean>
<!--Resin conf中引入数据源, GeliDao需要的数据源-->
<jee:jndi-lookup id="dataSource" jndi-name="jdbc/vino"/>
<!--注册注解并且开启,仅能够在已经在已经注册过的bean上面起作用-->
<!--<context:annotation-config />-->
<!--自动扫描注解的类并且注册Bean-->
<!--根据正则规则,该文件夹下的所有文件都自动装载,不需要写注解-->
<context:component-scan base-package="com.rsu.vino.dao">
<context:include-filter type="regex" expression=".*"/>
</context:component-scan>
<context:component-scan base-package="com.rsu.vino.service">
<context:include-filter type="regex" expression=".*"/>
</context:component-scan>
<!--自动扫描注解的类并且注册Bean-->
<!--根据正则规则,以下文件夹不会被扫描,需要通过写注解来注册Bean-->
<context:component-scan base-package="com.rsu.vino">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
</context:component-scan>
<!--注解事务-->
<aop:aspectj-autoproxy proxy-target-class="true"/>
<!--注解方式配置事务 start-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="list*" read-only="true" propagation="NOT_SUPPORTED" />
<tx:method name="get*" read-only="true" propagation="NOT_SUPPORTED" />
<tx:method name="find*" read-only="true" propagation="NOT_SUPPORTED" />
<tx:method name="page*" read-only="true" propagation="NOT_SUPPORTED" />
<tx:method name="count*" read-only="true" propagation="NOT_SUPPORTED" />
<tx:method name="exists*" read-only="true" propagation="NOT_SUPPORTED" />
<tx:method name="*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="vinoService" expression="execution(* com.rsu.vino.service.*.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="vinoService" />
</aop:config>
<!--注解方式配置事务 end-->
<!--Memcached配置-->
<bean id="mcc" class="com.danga.MemCached.MemCachedClient" p:sanitizeKeys="false" >
<constructor-arg value="vino"/>
</bean>
<!--配置Memcached的缓冲pool-->
<!--com.danga.MemCached.SockIOPool的constructor配置名字要和"com.danga.MemCached.MemCachedClient的constructor一样-->
<bean id="mccSocketIOPool" class="com.danga.MemCached.SockIOPool"
factory-method="getInstance"
init-method="initialize"
destroy-method="shutDown"
p:servers="${memcached.servers:=127.0.0.1:11211}"
p:maxConn="${memcached.maxConn:=50}"
p:initConn="${memcached.initConn:=10}"
p:socketConnectTO="${memcached.socketConnectTO:=800}"
p:socketTO="${memcached.socketTO:=500}"
p:maintSleep="${memcached.maintSleep:=3000}"
p:failover="${memcached.failover:=false}"
p:failback="${memcached.failback:=false}"
p:nagle="${memcached.nagle:=false}" >
<constructor-arg value="vino"/>
</bean>
</beans>
<jee:jndi-lookup id="props" jndi-name="java:comp/env/props"/>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<!-- 这里支持多种寻址方式:classpath和file -->
<value>classpath:/opt/demo/config/demo-db.properties</value>
<!-- 推荐使用file的方式引入(最好用绝对路径),这样可以将配置和代码分离 -->
<value>file:/opt/demo/config/demo-mq.properties</value>
<value>file:/opt/demo/config/demo-remote.properties</value>
<!-- 查找容器的配置,并且获取其路径字符串值-->
<value>file:#{@props}</value>
</list>
</property>
<property name="ignoreResourceNotFound" value="true"/>
<property name="ignoreUnresolvablePlaceholders" value="true"/>
<property name="valueSeparator" value=":=" />
</bean>
@zhanzhenchao
Copy link
Author

配置说明

  • 数据库资源获取
  • 数据库源配置
  • Spring 注解配置
  • Spring 事务配置
  • Memcached 缓冲配置

其他文件说明

applicationContext_PropertyPlaceholderConfigurer.xml 文件为多个配置文件资源获取的配置方法

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment