admin 管理员组

文章数量: 1184232


2024年3月7日发(作者:专业供应的资金系统)

spring配置文件各个属性详解

分类: spring 2012-08-09 11:25 9316人阅读 评论(2) 收藏 举报

springaophibernateattributesxhtmlwebsphere

目录(?)[+]

一、引用外部属性文件

class="tyPlaceholderConfigurer">

classpath:ties

classpath:ties

我们定义了一个PropertyPlaceholderConfigurer类的实例,并将其位置属性设置为我们的属性文件。该类被实现为Bean工厂的后处理器,并将使用定义在文件中的属性来代替所有的占位符(${...}value)。

注意:

而在spring2.5的版本中提供了一种更简便的方式,如:

1.

location="classpath:config/ties"/>

这样以后要使用属性文件中的资源时,可以使用${属性名}来获得。

二、常用数据源的配置

第一种是:DBCP数据源,(需要加入2个jar文件,在spring中的lib下jakarta-commons/和)主要配置如下:

class="ataSource">

value="">

value="${}">

第二种是:c3p0数据源,跟第一种一个类型,需加入包。

第三种是:JNDI数据源,配置在高性能的应用服务器(如WebLogic、WebSphere等)

1.

class="jectFactoryBean">

2.

value="java:comp/env/jdbc/bbt"/>

3.

从spring2.0开始提供jee命名空间,可以简化配置如下:

1.

三、配置事务管理器

1、Spring JDBC 和 iBatis事务管理器的配置

class="urceTransactionManager">

2、Hibernate3以上事务管理器的配置(先要集成hibernate,再配置事务管理器)

1.

2.

class="essionFactoryBean">

3.

4.

5.

6. classpath:

7.

8.

9.

10.

11.

12.

13.

14.

15.

16.

17.

class="ateTransactionManager">

18.

19.

ref="sessionFactory">

3、配置tx/aop声明式事务

1.

2.

3.

4.

5.

6.

7.

8.

别的例子,可以进行对比下:

rollback-for="ion" no-rollback-for="eException"/>

rollback-for="eException" />

rollback-for="ion" />

1.

2. ss.*.*(..))" />

3.

4.

对比:

e.*.*(..))" />

四、context:component-scan

请参考/ydwuli06/article/details/6993219,具体的自己还深入研究过

五、aop注解支持

六、缓存配置

class="eManagerFactoryBean">

class="eFacade">

文件:

timeToIdleSeconds="300" timeToLiveSeconds="600" maxElementsInMemory="1000"

maxElementsOnDisk="10" diskPersistent="true" diskExpiryThreadIntervalSeconds="300"

diskSpoolBufferSizeMB="100" memoryStoreEvictionPolicy="LRU" />

******************************************************************************************************************************************************************************

注解缓存的配置:

参考(出自/gaoligaoli/article/details/4282403):

关于spring实现ehcache有很多方法,很多都是利用aop来实现,我认为采用注解的方式更灵活,配置也更简洁。下面就是我利用spring-modules-0.9实现的注解缓存。

配置文件如下:

[xhtml] view plaincopyprint?

1.

2.

3. xmlns:xsi="/2001/XMLSchema-instance"

4. xmlns:context="/schema/context"

5. xmlns:aop="/schema/aop"

6. xmlns:tx="/schema/tx"

7. xmlns:ehcache="/schema/ehcache"

8. xsi:schemaLocation="/schema/beans

9. /schema/beans/

10. /schema/context

11. /schema/context/

12. /schema/aop

13. /schema/aop/

14. /schema/tx

15. /schema/tx/

16. /schema/ehcache

17. /schema/cache/">

18.

19.

20.

21.

22.

23.

24.

这里一定要注意:

xmlns:ehcache="/schema/ehcache"

/schema/ehcache

/schema/cache/

我就在这里花了很长时间,查了很多资料。网上的很多资料说这是spring-moduls的bug。很多朋友在这里总是报找到xsd文件。

在中加入

[xhtml] view plaincopyprint?

1.

2. maxElementsOnDisk="1000" eternal="true" overflowToDisk="true"

3. memoryStoreEvictionPolicy="LFU" />

***************************************************************************************************************************************************************************

七、


本文标签: 配置 属性 时间 缓存