本文实例为大家分享了Spring jndi数据源配置代码,供大家参考,具体内容如下
xml配置:
1
2
3
4
5
6
7
|
< bean id = "dataSource"
class = "org.springframework.jdbc.datasource.DriverManagerDataSource" >
< property name = "driverClassName" value = "oracle.jdbc.driver.OracleDriver" />
< property name = "url" value = "jdbc:oracle:thin:@xxx.xxx.xxx.xxx:1521:orcl" />
< property name = "username" value = "cba" />
< property name = "password" value = "***" />
</ bean >
|
在weblogic/jboss中配置好JNDI数据源后,上述节点改为:
1
2
3
4
5
|
< bean id = "dataSource" class = "org.springframework.jndi.JndiObjectFactoryBean" >
< property name = "jndiName" >
< value >java:/ssoDS</ value >
</ property >
</ bean >
|
其中:第3行的java:/ssoDS即为web容器中配置好的jndi数据源名称
其它地方不用任何修改,使用示例如下:
1
2
3
4
5
|
< beans:bean id = "userDetailsDao" class = "infosky.ckg.sso.dao.impl.UserDetailsDaoImpl" >
< beans:property name = "dataSource" ref = "dataSource" />
<!-- 登录错误尝试次数 -->
< beans:property name = "maxAttempts" value = "5" />
</ beans:bean >
|
在websphere 下的配置,参考一下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
<!-- 连接池数据源配置 -->
< bean id = "dataSource" class = "org.springframework.jndi.JndiObjectFactoryBean" >
< property name = "jndiName" >
< value >us_edbev</ value >
</ property >
</ bean >
<!-- end 连接池数据源配置 -->
< bean id = "sessionFactory" class = "org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" >
<!-- 配置Hibernate拦截器,自动填充数据的插入、更新时间 -->
< property name = "entityInterceptor" ref = "entityInterceptor" />
< property name = "dataSource" ref = "dataSource" />
< property name = "hibernateProperties" >
< value >
<!-- 设置数据库方言 -->
hibernate.dialect=${hibernate.dialect}
<!-- 设置自动创建|更新|验证数据库表结构
hibernate.hbm2ddl.auto=update
-->
<!-- 输出SQL语句到控制台 -->
hibernate.show_sql=true
<!-- 格式化输出到控制台的SQL语句 -->
hibernate.format_sql=${hibernate.format_sql}
<!-- 是否开启二级缓存 -->
hibernate.cache.use_second_level_cache=false
<!-- 配置二级缓存产品 -->
hibernate.cache.provider_class=org.hibernate.cache.OSCacheProvider
<!-- 是否开启查询缓存 -->
hibernate.cache.use_query_cache=false
<!-- 数据库批量查询数 -->
hibernate.jdbc.fetch_size=50
<!-- 数据库批量更新数 -->
hibernate.jdbc.batch_size=30
hibernate.autoReconnect=true
</ value >
</ property >
< property name = "annotatedClasses" >
< list >
.....
</ list >
</ property >
</ bean >
<!-- 缓存配置 -->
<!-- <oscache:config configLocation="classpath:oscache.properties" id="cacheProvider" />-->
<!-- <oscache:annotations providerId="cacheProvider">-->
<!-- <oscache:caching id="caching" cronExpression="0 1 * * *" refreshPeriod="86400" />-->
<!-- <oscache:flushing id="flushing" />-->
<!-- </oscache:annotations>-->
< bean id = "cacheManager" class = "org.springmodules.cache.provider.oscache.OsCacheManagerFactoryBean" >
< property name = "configLocation" value = "classpath:oscache.properties" />
</ bean >
<!-- 设置需要进行Spring注解扫描的类包 -->
< context:component-scan base-package = "cn.com.sinosoft" />
< context:component-scan base-package = "com.sinosoft" />
<!-- 使用AspectJ方式配置AOP -->
< aop:aspectj-autoproxy proxy-target-class = "true" />
< aop:config proxy-target-class = "true" />
<!-- 使用注解方式定义事务 -->
< tx:annotation-driven proxy-target-class = "true" transaction-manager = "transactionManager" />
<!-- 配置事务管理器 -->
< bean id = "transactionManager" class = "org.springframework.orm.hibernate3.HibernateTransactionManager" >
< property name = "sessionFactory" ref = "sessionFactory" />
</ bean >
<!-- 配置事务传播特性 -->
< tx:advice id = "transactionAdvice" transaction-manager = "transactionManager" >
< tx:attributes >
< tx:method name = "save*" propagation = "REQUIRED" />
< tx:method name = "delete*" propagation = "REQUIRED" />
< tx:method name = "update*" propagation = "REQUIRED" />
< tx:method name = "get*" read-only = "true" />
< tx:method name = "load*" read-only = "true" />
< tx:method name = "find*" read-only = "true" />
< tx:method name = "*" read-only = "true" />
</ tx:attributes >
</ tx:advice >
<!-- 配置哪些类的哪些方法参与事务 -->
< aop:config >
< aop:advisor pointcut = "execution(* cn.com.sinosoft.service..*.*(..))" advice-ref = "transactionAdvice" />
</ aop:config >
<!-- 配置freemarkerManager -->
< bean id = "freemarkerManager" class = "cn.com.sinosoft.util.FTLManager" />
<!-- 配置JCaptcha验证码功能 -->
< bean id = "captchaService" class = "com.octo.captcha.service.image.DefaultManageableImageCaptchaService" >
< property name = "captchaEngine" >
< bean class = "cn.com.sinosoft.common.JCaptchaEngine" />
</ property >
<!-- 验证码过期时间 -->
< property name = "minGuarantedStorageDelayInSeconds" value = "600" />
</ bean >
|
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。