Tomcat 6 using JNDI global DBCP
This setting gives me a hard time.
I have gone through Tomcat 6 document about JNDI and JDBC so many times.
But I get this work by reading many forums.
I think the documents provided by tomcat is confusing and maybe out of sync. to the current version.
I am going straight to the solution.
Add this in your tomcat\conf\server.xml, the parameters are set according to your situation
<GlobalNamingResources>
<!-- Editable user database that can also be used by
UserDatabaseRealm to authenticate users
--> <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/javatest?autoReconnect=true"/>
</GlobalNamingResources>
Add this to your tomcat\conf\context.xml
<ResourceLink name="jdbc/TestDB" global="jdbc/TestDB" type="javax.sql.DataSource"/>
Nothing needs to be done to you per-web web.xml.
It is not what tomcat documentation mention in server.xml <host><context>…</context></host>
Maybe that works for per-web-jndi setting but not for global one.
This look like easy setting, but it takes me lots of time.
P.S. I am newbie to tomcat, haha.
One more thing, If you are using Spring HibernateDaoSupport.
The value for jndiName for Tomcat is different from other like JBoss.
JBoss : java:jdbc/TestSpring
Tomcat: java:comp/env/jdbc/TestSpring
that is
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/TestSpring</value>
</property>
</bean>
Java AS, Container的體驗
早前因為研究portlet用到Jboss AS, Portal.
但他的startup超慢,因為要處理很多東西和支持EJB3吧
但如果自己玩開發,聽VP的Angus說,他們只用Tomcat,20秒不到就reboot完了.
我自己又還沒用到EJB,只是用來玩,那就想試一下Tomcat,以後要用web service再來弄JBoss AS吧.
一用之下發現Tomcat真的爽很多,幾秒就能讓用start起來試你的web app了 .