Moving contents of META-INF/context.xml to tomcat/conf

好久不见. 提交于 2019-12-11 07:35:10

问题


We are trying to take the environment specific configuration settings out of our war files, so we can deploy the same war file to dev/test/prod tomcat servers and not have to change the contents of the war config file.

When I move the META-INF/context.xml for the database connection to the conf/server.xml the database connection no longer works, with the following error, anyone know why this would be?

server.xml:

<GlobalNamingResources>
    ....
    <Resource
            url="jdbc:oracle:thin:@hostname:1521/something"
            username="username"
            name="jdbc/mydb"
            password="password"
            auth="Container"
            driverClassName="oracle.jdbc.driver.OracleDriver"
            maxActive="5" maxIdle="2" maxWait="10000"
            removeAbandoned="true"
            type="javax.sql.DataSource"
            />
</GlobalNamingResources>

The error is as follows:

INFO: Deploying web application directory ROOT
Problem reading system configuration. Cannot create JDBC driver of class '' for connect URL 'null' (java.io.IOException: Cannot create JDBC driver of class '' for connect URL 'null')
java.io.IOException: Cannot create JDBC driver of class '' for connect URL 'null'
    at au.edu.unimelb.helper.SettingManager.loadSettings(SettingManager.java:212)
    at au.edu.unimelb.helper.SettingManager.<init>(SettingManager.java:53)

(And yes the odjbc6.jar file is in $TOMCAT_HOME/lib/)


回答1:


Finally worked it out, the tomcat documentation was slightly misleading. You can put the contents of your META-INF/context.xml straight into $TOMCAT_HOME/conf/context.xml and it works just fine.




回答2:


There might be missing a <ResourceLink> in context.xml (either in the web application's META-INF/context.xml or in $TOMCAT_HOME/conf/context.xml, like so:

        <ResourceLink name="jdbc/mydb"
              type="javax.sql.DataSource"
              global="jdbc/mydb"/> 


来源:https://stackoverflow.com/questions/5656756/moving-contents-of-meta-inf-context-xml-to-tomcat-conf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!