部署WAR文件时出现Tomcat 7.0.52 JNDI错误

时间:2014-03-13 05:12:09

标签: java apache sql-server-2008 tomcat jndi

数据库是:MSSQL 2008 R2 OS = Windows Server 2008 R2

server.xml中的全局资源是:

<Resource name="data source name" auth="Container"  type="javax.sql.DataSource" username="myuser" password="abc@xyz"  driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" url="jdbc:sqlserver://host:1433;databaseName=test1;selectMethod=cursor"  maxWait="30000" maxActive="32" maxIdle="4" initialSize="4"  timeBetweenEvictionRunsMillis="600000" minEvictableIdleTimeMilllis="600000" />
  </GlobalNamingResources>

<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
               resourceName="UserDatabase"/>

资源价值是否存在冲突或是否还有其他问题?我也尝试在资源名称标记中添加tomcat用户文件,但也无法正常工作。 我还在context.xml文件中定义了数据源名称。

错误日志是:

2014年3月12日下午5:19:53 org.apache.catalina.realm.UserDatabaseRealm startInternal 严重:在关键UserDatabase下查找UserDatabase的异常 javax.naming.NameNotFoundException:名称[UserDatabase]未绑定在此Context中。无法找到[UserDatabase]。     在org.apache.naming.NamingContext.lookup(NamingContext.java:819)     在org.apache.naming.NamingContext.lookup(NamingContext.java:167)     在org.apache.catalina.realm.UserDatabaseRealm.startInternal(UserDatabaseRealm.java:253)     在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)     在org.apache.catalina.realm.CombinedRealm.startInternal(CombinedRealm.java:201)     在org.apache.catalina.realm.LockOutRealm.startInternal(LockOutRealm.java:120)     在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)     在org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1109)     在org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:300)     在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)     在org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)     在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)     在org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:731)     在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)     在org.apache.catalina.startup.Catalina.start(Catalina.java:689)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)     at java.lang.reflect.Method.invoke(Unknown Source)     在org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:321)     在org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:455)

2014年3月12日下午5:19:53 org.apache.catalina.realm.CombinedRealm startInternal 严重:无法启动“org.apache.catalina.realm.UserDatabaseRealm / 1.0”领域 org.apache.catalina.LifecycleException:无法启动组件[Realm [UserDatabaseRealm]]     在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154)     在org.apache.catalina.realm.CombinedRealm.startInternal(CombinedRealm.java:201)     在org.apache.catalina.realm.LockOutRealm.startInternal(LockOutRealm.java:120)     在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)     在org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:1109)     在org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:300)     在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)     在org.apache.catalina.core.StandardService.startInternal(StandardService.java:443)     在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)     在org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:731)     在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)     在org.apache.catalina.startup.Catalina.start(Catalina.java:689)     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)     at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)     at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)     at java.lang.reflect.Method.invoke(Unknown Source)     在org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:321)     在org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:455) 引起:org.apache.catalina.LifecycleException:在UserDatabase下找不到UserDatabase组件     在org.apache.catalina.realm.UserDatabaseRealm.startInternal(UserDatabaseRealm.java:262)     在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)     ......还有17个

1 个答案:

答案 0 :(得分:1)

你已经破坏了server.xml。如果您有<Realm>指向“UserDatabase”,那么您需要有一个名为“UserDatabase”的<Resource>。这是默认配置:

<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" />

如果您想为<Realm>使用关系数据库,则需要更改配置以指向该数据库,而您需要使用DataSourceRealm