tomcat7配置数据源
2015-01-21 10:51
190 查看
在tomcat7配置数据源
1. tomcat\conf\context.xml中配置
2. tomcat\conf\server.xml配置
3. 如果使用spring,在 application-context.xml中的配置
1. tomcat\conf\context.xml中配置
<?xml version='1.0' encoding='utf-8'?> <Context> <WatchedResource>WEB-INF/web.xml</WatchedResource> <ResourceLink name="DS_APP_TEST" global="DS_APP_TEST" type="javax.sql.DataSource"/></Context>
2. tomcat\conf\server.xml配置
<?xml version='1.0' encoding='utf-8'?> <Server port="8005" shutdown="SHUTDOWN"> <!-- Security listener. Documentation at /docs/config/listeners.html <Listener className="org.apache.catalina.security.SecurityListener" /> --> <!--APR library loader. Documentation at /docs/apr.html --> <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html --> <Listener className="org.apache.catalina.core.JasperListener" /> <!-- Prevent memory leaks due to use of particular java/javax APIs--> <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /> <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" /> <GlobalNamingResources> <!-- Editable user database that can also be used by UserDatabaseRealm to authenticate users --> <Resource name="UserDatabase" auth="Container" type="org.apache.catalina.UserDatabase" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" pathname="conf/tomcat-users.xml" /> <Resource name="DS_APP_TEST" type="javax.sql.DataSource" driverClassName="oracle.jdbc.driver.OracleDriver" url="jdbc:oracle:thin:@192.168.0.1:1521/test" username="test" password="test" maxIdle="40" maxWait="4000" maxActive="250" removeAbandoned="true" removeAbandonedTimeout="180" logAbandoned="true" testWhileIdle="true" testOnBorrow="true" testOnReturn="false" validationQuery="SELECT 1 from dual" validationInterval="30000" timeBetweenEvictionRunsMillis="30000" factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" /> </GlobalNamingResources> <Service name="Catalina"> <Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> <Engine name="Catalina" defaultHost="localhost"> <Realm className="org.apache.catalina.realm.LockOutRealm"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/> </Realm> <Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true"> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t "%r" %s %b" /> </Host> </Engine> </Service> </Server>
3. 如果使用spring,在 application-context.xml中的配置
<?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:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:d="http://www.bstek.com/dorado/schema" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.bstek.com/dorado/schema http://www.bstek.com/dorado/schema/spring-dorado-7.0.xsd "> <d:import-dorado /> <!-- properties 配置 --> <context:property-placeholder location="classpath:/config/jdbc.properties"/> <!-- 配置启用spring 注解 --> <context:annotation-config/> <!-- 数据源配置 --> <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean"> <property name="jndiName"> <value>DS_APP_TEST</value> </property> <property name="resourceRef"> <value>true</value> </property> </bean> .... </beans>
相关文章推荐
- Tomcat7配置数据源
- Tomcat7配置数据源
- tomcat7 配置数据源
- Tomcat7配置数据源
- Tomcat7配置数据源
- 在Tomcat7中配置数据源
- tomcat7用jndi配置数据源出现java.lang.NoSuchMethodException: org.apache.catalina.deploy.WebXml addResourceRef
- Tomcat7配置数据源
- Tomcat7配置数据源
- Tomcat7配置数据源
- Tomcat7配置数据源
- tomcat7配置数据源异常---Cannot create JDBC driver of class '' for connect URL 'null'
- Tomcat7配置数据源
- 在struts-config.xml中配置数据源
- JBoss4.0数据源配置大全
- Tomcat5数据源配置--tomcat笔记2
- 在JBOSS 4.0中配置MsSqlServer 数据源
- 数据源配置心得体会
- tomcat5.0的数据源配置。