spring mvc项目,部署tomcat 中,使用jndi数据源
2017-10-26 10:58
489 查看
最近部署项目时,有几个项目使用同一个数据源,不想在每个项目中都配置一边,所以就想用jndi数据源的方式,tomcat是8.5,spring是最新版本,配置如下:
conf/context.xml全局配置:
web.xml增加配置:
spring applicationcontext.xml配置:
resourceRef必须配置,否则报错
另外官网说要这么写:java:/comp/env/名字,改成下面这样:
我也测试了,可以用,网上搜到很多,基本都不能用,不知道是不是版本的问题。
官网配置文档,在这里
支持的属性,可以在这里
conf/context.xml全局配置:
<Context> <!-- Default set of monitored resources. If one of these changes, the --> <!-- web application will be reloaded. --> <WatchedResource>WEB-INF/web.xml</WatchedResource> <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource> <!-- Uncomment this to disable session persistence across Tomcat restarts --> <!-- <Manager pathname="" /> --> <Resource name="test" auth="Container" type="javax.sql.DataSource" maxTotal="100" maxIdle="15" maxWaitMillis="10000" username="test" password="test" driverClassName="com.mysql.cj.jdbc.Driver" url="jdbc:mysql://localhost"/> </Context>
web.xml增加配置:
<resource-ref> <description>Datasource</description> <res-ref-name>test</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
spring applicationcontext.xml配置:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName"> <value>test</value> </property> <property name="resourceRef"> <value>true</value> </property> </bean>
resourceRef必须配置,否则报错
Name [test] is not bound in this Context. Unable to find [test]
另外官网说要这么写:java:/comp/env/名字,改成下面这样:
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName"> <value>java:/comp/env/test</value> </property> <property name="resourceRef"> <value>true</value> </property> </bean>
我也测试了,可以用,网上搜到很多,基本都不能用,不知道是不是版本的问题。
官网配置文档,在这里
支持的属性,可以在这里
相关文章推荐
- WEB项目中,让FineReport6.5使用Tomcat下所配置的JNDI数据源
- tomcat+spring+jndi同时部署多个项目配置多数据源
- Tomcat 6 部署工程总结,使用JNDI数据源配置
- tomcat中通过JNDI数据源配置使用
- 使用maven部署项目到tomcat 7
- tomcat中通过JNDI数据源配置使用
- spring下tomcat使用weblogic配置的jndi数据源
- 如何让项目使用myEclipse部署在tomcat的ROOT目录下
- 在spring+hibernate中使用tomcat5.5的jndi数据源
- 使用ant脚本,对java web项目,编译、打包、发布部署到tomcat
- 在Eclipse中使用Tomcat部署Web项目
- WebLogic-JNDI数据源+WEB项目使用
- tomcat中通过JNDI数据源配置使用
- 关于WEB项目部署时TOMCAT和JDK的使用的方法
- 使用maven部署项目到tomcat 7
- 在TOMCAT中使用JNDI连接数据源
- Tomcat里使用JNDI设置Derby数据源
- 使用Ant构建web项目 从编译到测试 生成测试报告 打包 邮件发送 远程下载tomcat 部署运行一条龙服务之ant脚本
- Tomcat里使用JNDI设置Derby数据源