server.xml
<GlobalNamingResources>
<Resource auth="Container" description="User Database" factory=org.apache.tomcat.jdbc.pool.DataSourceFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type=org.apache.Catalina.UserDatabase" />
<Resource name="jdbc/ds" auth="Container" type="javax.sql.DataSource"
maxTotal="100" maxIdle="30" maxWaitMillis="10000" maxWait="10000" maxActive="100"
username="test" password="test123" jdbcInterceptors="ConnectionState;StatementFinalizer"
url="jdbc:oracle:thin:@localhost:1521:SPRINGTEST/" validationQuery="select 1 from dual" />
</ GlobalNamingResources>
tomcat-users.xml
<?xml version="1.0" encoding="UTF-8"?>
<tomcat-users version="1.0" xmlns="http://tomcat.apache.org/xml"
xmlns="http://www.w3.org/2001/XMLSchema-instance"
xsi=schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd">
<role rolename="tomcat"/>
<role rolename="role1"/>
<role username="tomcat" password="tomcat" roles="tomcat"/>
<role username="both" password="tomcat" roles="tomcat, role1"/>
<role username="role1" password="tomcat" roles="role1"/>
</tomcat-users>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="4.0" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd">
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/ds</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
context.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Web application will be reloaded. -->
<!-- <WatchedResource>WEB-INF/web.xml</WatchedResource> -->
<WatchedResource>WEB-INF/tomcat-web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
<ResourceLink global="jdbc/ds" name="jdbc/ds" type="javax.sql.DataSource"/>
</Context>
错误消息
org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory getObjectInstance
INFO: Name = DS Ignoring unknown property: value of
"org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptorStatementFinalizer" for "jdbcInterceptors" property
org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory getObjectInstance
INFO: Name = DS Ignoring unknown property: value of "30000" for "validationInterval" property
org.apache.tomcat.dbcp.dbcp2.BasicDataSourceFactory getObjectInstance
INFO: Name = DS Ignoring unknown property: value of "true" for "jmxEnabled" property
org.apache.tomcat.jdbc.pool.DataSourceFactory getObjectInstance
WARNING: org.apache.catalina.UserDatabase is not a valid class name/type for this JNDI factory.
org.apache.catalina.mbeans.GlobalResourcesLifecyclelistener createMBeans
SEVERE: Unexpected error creating MBeans
java.lang.NullPointerException
at org.apache.naming.NamingContextBindingsEnumeration.nextElementInternal(NamingContextBindingsEnumeration.java:129)
at org.apache.naming.NamingContextBindingsEnumeration.next(Naming ContextBindingsEnumeration.java:71)
at org.apache.naming.NamingContextBindingsEnumeration.next(NamingContextBindingsEnumeration.java:34)
at org.apache.catalina.beans.GlobalResourcesLifecyclelistener.createBeans(GlobalResourceslifecyclelistener.java:127)
at org.apache.catalina.mbeans.GlobalResourcesLifecyclelistener.createMBeans(GlobalResourcesLifecyclelistener.java:101)
at org.apache.catalina.mbeans.GlobalResourcesLifecyclelistenerlifecycleEvent(GlobalResourceslifecyclelistener.java:76)
at org.apache.catalina.util.LifecycleBase.firelifecycleEvent(LifecycleBase.java:123)
at org.apache.catalina.util.LifecycleBase.setStateInternal(LifecycleBase.java:423)
at org.apache.catalina.util.LifecycleBase.setState(Lifecyclebase.java.366)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:923)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.startup.Catalina.start(Catalina.java:772)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:342)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:473)
org.apache.catalina.core.StandardService startInternal
INFO: Starting service [Catalina]
org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet engine: [Apache Tomcat/9.0.43]
org.apache.catalina.realm.CombinedRealm startInternal
SEVERE: Failed to start [org.apache.catalina.realm.UserDatabaseRealm] realm
org.apache.catalina.LifecycleException: No UserDatabase component found under key [UserDatabase]
at org.apache.catalina.realm.UserDatabaseRealm.startInternal(UserDatabaseRealm.java:282)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.realm.CombinedRealm.startInternal(CombinedRealm.java:248)
at org.apache.catalina.realm.LockOutRealm.startInternal(LockOutRealm.java:116)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:902)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.Standard Service.startInternal(StandardService.java:434)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardServer.startInternal (StandardServer.java:930)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.startup. Catalina.start(Catalina.java:772)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java: 342)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:473)
我正在使用tomcat 9.0版,编译代码时收到错误消息严重:创建MBean java.lang.nullpointerexception时出现意外错误严重:无法启动[org.apache.catalina.realm.userdatabaserealm]realm org.apache.catalina.LifecycleeException:在键[userdatabase]下找不到userdatabase组件
请帮助我了解设置中缺少的内容。
1条答案
按热度按时间jtjikinw1#
这个
UserDatabaseRealm
(参见文档)需要类型为的资源org.apache.catalina.UserDatabase
(不要与数据库连接池混淆,数据库连接池类型为javax.sql.DataSource
).在配置中,您提供了错误的对象工厂类名:您使用了
org.apache.tomcat.jdbc.pool.DataSourceFactory
,它创建tomcat jdbc连接池,而不是org.apache.catalina.users.MemoryUserDatabaseFactory
.只需使用:
这个
pathname
属性的默认值为conf/tomcat-users.xml
,因此可以省略它。备注:日志中的警告“ds忽略未知属性”与
jdbc/ds
您配置的数据源。默认情况下,tomcat使用dbcp2连接池(参见文档),而您提供了tomcat jdbc连接池的属性(参见文档)。