本文實例為大家分享了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 > |
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持服務器之家。