Linux 上带有 WAR 文件的 Tomcat 6 的 JNDI 资源问题

发布于 2024-09-30 09:55:53 字数 1584 浏览 2 评论 0原文

我对 Tomcat 和 Java Web 开发相当陌生,并且因为我遇到的问题而碰壁。

我有一个在本地机器(windows xp)上运行良好的 Web 应用程序,我安装了 Tomcat 6,并将 WAR 文件部署到 webapps 文件夹和 c:/apache-tomcat-6.0.18/conf/Catalina/localhost 中/ 目录我有“myApp.xml”。

myApp.xml 包含以下内容:

<Context path="/myApp" docBase="/myApp.war" debug="1" reloadable="true" cookies="true">
  <Resource name="jdbc/sql-connection" scope="Shareable" type="javax.sql.DataSource" auth="Container" username="test" password="test" factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" driverClassName="net.sourceforge.jtds.jdbc.Driver" url="jdbc:jtds:sqlserver://xxxx:xxxx;appName=myApp" removeAbandoned="true" logAbandoned="true" /> 
  </Context>

然后在我的 Web 应用程序中,我的 applicationContext 文件中有以下信息

<bean id="myDatasource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName">
            <value>java:comp/env/jdbc/sql-connection</value>
        </property>
    </bean> 

现在我已经从在本地机器上一切正常到将其部署在 Linux 机器上,但是当我将其部署在在那里,使用完全相同的设置,只是 tomcat 从“opt/apache-tomcat-6.0.18”运行。每次我尝试在盒子上启动 Tomcat 时,它都会解压 WAR 文件,但不会启动它,并且每当我尝试通过管理器启动它时都会出现以下错误:

Error creating bean with name 'myDatasource' defined in file [/opt/apache-tomcat-6.0.18/webapps/myApp/WEB-INF/classes/applicationContext.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name jdbc is not bound in this Context

我尝试在互联网上寻找答案,但似乎没有任何结果遇到完全相同的问题,并且 tomcat 配置文件和 Web 应用程序之间的名称似乎匹配。

I'm fairly new to Tomcat and Java web development and am banging my head against a wall with an issue im experiencing.

I have a web application that works fine on my local box (windows xp), I have Tomcat 6 installed with the WAR file deployed to the webapps folder and within the c:/apache-tomcat-6.0.18/conf/Catalina/localhost/ directory i have the "myApp.xml".

The myApp.xml contains the following:

<Context path="/myApp" docBase="/myApp.war" debug="1" reloadable="true" cookies="true">
  <Resource name="jdbc/sql-connection" scope="Shareable" type="javax.sql.DataSource" auth="Container" username="test" password="test" factory="org.apache.tomcat.jdbc.pool.DataSourceFactory" driverClassName="net.sourceforge.jtds.jdbc.Driver" url="jdbc:jtds:sqlserver://xxxx:xxxx;appName=myApp" removeAbandoned="true" logAbandoned="true" /> 
  </Context>

Then within my web app i have the following info within my applicationContext file

<bean id="myDatasource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName">
            <value>java:comp/env/jdbc/sql-connection</value>
        </property>
    </bean> 

Now i've gone from it all working fine on my local box to deploying it on a Linux box, however when I deploy it on there, with exactly the same setup just tomcat is running from "opt/apache-tomcat-6.0.18". Every time I try to start Tomcat on the box it will unpack the WAR file but wont start it, and gives me the following error whenever i try to start it through the manager:

Error creating bean with name 'myDatasource' defined in file [/opt/apache-tomcat-6.0.18/webapps/myApp/WEB-INF/classes/applicationContext.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name jdbc is not bound in this Context

Ive tried looking all over the internet for an answer but nothing seems to have the exact same issue, and the names seem to match between the tomcat config file and the web app.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

说谎友 2024-10-07 09:55:53

首先,Tomcat 不理解 myApp.xml (除非您明确地将其指向它,但我不知道如何实现)。 Tomcat 基于上下文工作,可以为您的网络应用程序配置该上下文。 Tomcat 只允许部署 Web 应用程序存档 (WAR) 文件。

要为您的应用程序创建上下文,请在您的 Web 应用程序 META-INF创建一个 context.xml(全部小写字母,区分大小写)文件> 文件夹。

配置上下文的参考指南可以在 Tomcat 6 Config/Context。您将看到属性 debug弃用

Tomcat 6 的 JNDI 资源操作指南也可以提供

在 META-INF 文件夹中创建 context.xml 后,将以下代码(取自示例)粘贴到下面:(

<Context path="/myApp" docBase="/myApp.war" reloadable="true" cookies="true">
    <Resource name="jdbc/sql-connection" type="javax.sql.DataSource" auth="Container" username="test" password="test" driverClassName="net.sourceforge.jtds.jdbc.Driver" url="jdbc:jtds:sqlserver://xxxx:xxxx;appName=myApp" removeAbandoned="true" logAbandoned="true" /> 
</Context>

默认情况下,Tomcat 使用 PoolableDataSource 进行连接池)。

完成后,在 WEB-INF/web.xml 中配置 。这将允许您创建可共享范围。请参阅 链接 “http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html”rel="nofollow">Tomcat 6 JNDI,操作方法。

我希望这对你有帮助。

First of all, Tomcat doesn't understand myApp.xml (unless you explicitly points it to it, which I don't know how). Tomcat works based on context, which can be configured for your web application. Tomcat allows only deployment of Web Aplication Archive (WAR) file.

To create a context for your application, create a context.xml (all small caps, case-sensitive) file inside your Web application META-INF folder.

Your reference guide to configuring context can be found on Tomcat 6 Config/Context. You will see that attribute debug is deprecated.

The JNDI Resources HOW-TO for Tomcat 6 is also available.

Once you have created your context.xml inside your META-INF folder, paste the following code (taken from your example) below:

<Context path="/myApp" docBase="/myApp.war" reloadable="true" cookies="true">
    <Resource name="jdbc/sql-connection" type="javax.sql.DataSource" auth="Container" username="test" password="test" driverClassName="net.sourceforge.jtds.jdbc.Driver" url="jdbc:jtds:sqlserver://xxxx:xxxx;appName=myApp" removeAbandoned="true" logAbandoned="true" /> 
</Context>

(By default, Tomcat uses PoolableDataSource for Connection Pooling).

Once you're done, config your <resource-env-ref> in your WEB-INF/web.xml. That will allow you to create Shareable scope. Please refer to the link provided on Tomcat 6 JNDI, HOW-TO.

I hope this helps you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文