使用 IntelliJ 部署到远程 Tomcat 实例的 Web 应用程序找不到 JNDI 资源 (javax.naming.NameNotFoundException)
Web application deployed to remote Tomcat instance using IntelliJ cannot find JNDI resource (javax.naming.NameNotFoundException)
我正在使用 IntelliJ IDEA 14.0.2 启动本地 Tomcat 7.0.42 实例,然后使用远程 Tomcat 运行配置单独部署 WAR。我的 Web 应用程序无法通过 JNDI 获取资源,我怀疑这是因为它无法远程连接到 JMX,尽管如果我注释掉 JNDI 查找,WAR 部署没有问题。如果我在同一个本地 Tomcat 运行配置中包含 Tomcat 启动和 WAR 部署,查找工作正常。
以下是我认为相关的所有详细信息,如果您需要其他任何信息,请告诉我。感谢您的帮助!
本地Tomcat运行配置:
HTTP端口:8080
JMX 端口:11444
JAVA_OPTS
-Dcatalina.base="C:\apache-tomcat-7.0.42"
-Dcatalina.home="C:\apache-tomcat-7.0.42"
-Dwtp.deploy="C:\apache-tomcat-7.0.42\wtpwebapps"
-Djava.endorsed.dirs="C:\apache-tomcat-7.0.42\endorsed"
-Depf.config.root="C:/dev/appConfig"
-Dactivemq.conf="C:/dev/appConfig/app-common-config/environment/dev-win/activemq"
-Dactivemq.data="C:/dev/activemq"
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=11444
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dwebconsole.type=properties
-Dwebconsole.jms.url=tcp://localhost:61616
-Dwebconsole.jmx.url=service:jmx:rmi:///jndi/rmi://localhost:11444/jmxrmi
-Dwebconsole.jmx.user=system
-Dwebconsole.jmx.password=password
-Dlog4j.configuration=file:C:\dev\appConfig\logging\log4j.xml
-Djava.util.logging.config.file="C:\apache-tomcat-7.0.42\conf\logging.properties"
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.security.auth.login.config="C:\apache-tomcat-7.0.42\conf\jaas.config"
-Xms2048m
-Xmx2048m
-XX:NewSize=512m
-XX:MaxNewSize=512m
-XX:PermSize=512m
-XX:MaxPermSize=512m
CATALINA_OPTS
-Dactivemq.conf=C:/dev/appConfig/app-common-config/environment/dev/activemq
-Dactivemq.data=C:/dev/appConfig/activemq-data
-Dlog4j.configuration=file:C:/dev/appConfig/logging/log4j.xml
-Djava.security.auth.login.config=C:/apache-tomcat-7.0.42/conf/jaas.config
远程Tomcat运行配置:
JMX 端口:11444
远程暂存:相同的文件系统
主机:相同的文件系统
远程连接主机: localhost
远程连接端口:8080
部署: my-web:war
catalina.properties
## JMS Connection Factory
JMS.connectionFactory.factoryName=jms/jms.connectionFactory
JMS.connectionFactory.auth=Container
JMS.connectionFactory.brokerName=ActiveMQBroker
JMS.connectionFactory.brokerURL=tcp://localhost:61616
JMS.connectionFactory.factory=org.apache.activemq.jndi.JNDIReferenceFactory
JMS.connectionFactory.type=org.apache.activemq.ActiveMQConnectionFactory
JMS.connectionFactory.typeInterface=javax.jms.ConnectionFactory
## Local JMS Queue
JMS.queue.auth=Container
JMS.queue.name=jms/my.queue
JMS.queue.physicalName=my.queue
JMS.queue.factory=org.apache.activemq.jndi.JNDIReferenceFactory
JMS.queue.type=org.apache.activemq.command.ActiveMQQueue
context.xml
<ResourceLink global="${JMS.connectionFactory.factoryName}" name="${JMS.connectionFactory.factoryName}" type="${JMS.connectionFactory.typeInterface}"/>
<ResourceLink global="${JMS.queue.name}" name="${JMS.queue.name}" />
server.xml
<Resource auth="${JMS.connectionFactory.auth}"
brokerName="${JMS.connectionFactory.brokerName}" brokerURL="${JMS.connectionFactory.brokerURL}"
description="JMS Connection Factory" factory="${JMS.connectionFactory.factory}"
name="${JMS.connectionFactory.factoryName}" type="${JMS.connectionFactory.type}" />
<Resource auth="${JMS.queue.auth}" description="Outbound Queue"
factory="${JMS.queue.factory}" name="${JMS.queue.name}"
physicalName="${JMS.queue.physicalName}" type="${JMS.queue.type}" />
localhost:8080/manager/text/resources
OK - Listed global resources of all types
jms/jms.connectionFactory:org.apache.activemq.ActiveMQConnectionFactory
jms/my.queue:org.apache.activemq.command.ActiveMQQueue
UserDatabase:org.apache.catalina.users.MemoryUserDatabase
JNDI 查找
@Bean(name = {"jndiObjectFactory"})
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
@Profile("default")
public JndiObjectFactoryBean jndiObjectFactory() {
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
jof.setResourceRef(true);
jof.setJndiName("jms.connectionFactory");
Properties jndiProps = new Properties();
jndiProps.put("java.naming.factory.initial", "org.apache.naming.java.javaURLContextFactory");
jof.setJndiEnvironment(jndiProps);
return jof;
}
错误
SEVERE: Exception sending context initialized event to listener instance of class
org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'TestController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.me.test.factory.TestFactory com.me.test.tester.web.controller.TestController.testFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'TestFactory': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jndiObjectFactory' defined in class path resource [com/me/test/SpringConfig.class]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [jms.connectionFactory] is not bound in this Context. Unable to find [jms.connectionFactory].
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1551)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:622)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:569)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1487)
at javax.management.remote.rmi.RMIConnectionImpl.access0(RMIConnectionImpl.java:97)
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1328)
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1420)
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:848)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322)
at sun.rmi.transport.Transport.run(Transport.java:177)
at sun.rmi.transport.Transport.run(Transport.java:174)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:556)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:811)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:670)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.me.test.factory.TestFactory com.me.test.tester.web.controller.TestController.testFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'TestFactory': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jndiObjectFactory' defined in class path resource [com/me/test/SpringConfig.class]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [jms.connectionFactory] is not bound in this Context. Unable to find [jms.connectionFactory].
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:508)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
... 56 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'TestFactory': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jndiObjectFactory' defined in class path resource [com/me/test/SpringConfig.class]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [jms.connectionFactory] is not bound in this Context. Unable to find [jms.connectionFactory].
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:407)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1017)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:960)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:858)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480)
... 58 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jndiObjectFactory' defined in class path resource [com/me/test/SpringConfig.class]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [jms.connectionFactory] is not bound in this Context. Unable to find [jms.connectionFactory].
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:205)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:991)
at com.me.test.factory.TestQueueFactory.newInstance(TestQueueFactory.java:45)
at com.me.test.factory.TestFactory.createEmitter(TestFactory.java:178)
at com.me.test.factory.TestFactory.readConfigurationFromPropertiesFile(TestFactory.java:155)
at com.me.test.factory.TestFactory.init(TestFactory.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:349)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:300)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:133)
... 70 more
Caused by: javax.naming.NameNotFoundException: Name [jms.connectionFactory] is not bound in this Context. Unable to find [jms.connectionFactory].
at org.apache.naming.NamingContext.lookup(NamingContext.java:820)
at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:158)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at org.springframework.jndi.JndiTemplate.doInContext(JndiTemplate.java:155)
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:179)
at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:104)
at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:106)
at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:231)
at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:217)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)
... 86 more
这只是我的一个愚蠢错误,我不确定为什么它以前作为本地 tomcat 运行 配置工作。我回去尝试那样做,但我得到了同样的错误。
这仅仅是因为当我试图查找时 JNDI 名称应该是 "jms/jms.connectionFactory" "jms.connectionFactory"。
我正在使用 IntelliJ IDEA 14.0.2 启动本地 Tomcat 7.0.42 实例,然后使用远程 Tomcat 运行配置单独部署 WAR。我的 Web 应用程序无法通过 JNDI 获取资源,我怀疑这是因为它无法远程连接到 JMX,尽管如果我注释掉 JNDI 查找,WAR 部署没有问题。如果我在同一个本地 Tomcat 运行配置中包含 Tomcat 启动和 WAR 部署,查找工作正常。
以下是我认为相关的所有详细信息,如果您需要其他任何信息,请告诉我。感谢您的帮助!
本地Tomcat运行配置:
HTTP端口:8080
JMX 端口:11444
JAVA_OPTS
-Dcatalina.base="C:\apache-tomcat-7.0.42"
-Dcatalina.home="C:\apache-tomcat-7.0.42"
-Dwtp.deploy="C:\apache-tomcat-7.0.42\wtpwebapps"
-Djava.endorsed.dirs="C:\apache-tomcat-7.0.42\endorsed"
-Depf.config.root="C:/dev/appConfig"
-Dactivemq.conf="C:/dev/appConfig/app-common-config/environment/dev-win/activemq"
-Dactivemq.data="C:/dev/activemq"
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=11444
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dwebconsole.type=properties
-Dwebconsole.jms.url=tcp://localhost:61616
-Dwebconsole.jmx.url=service:jmx:rmi:///jndi/rmi://localhost:11444/jmxrmi
-Dwebconsole.jmx.user=system
-Dwebconsole.jmx.password=password
-Dlog4j.configuration=file:C:\dev\appConfig\logging\log4j.xml
-Djava.util.logging.config.file="C:\apache-tomcat-7.0.42\conf\logging.properties"
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Djava.security.auth.login.config="C:\apache-tomcat-7.0.42\conf\jaas.config"
-Xms2048m
-Xmx2048m
-XX:NewSize=512m
-XX:MaxNewSize=512m
-XX:PermSize=512m
-XX:MaxPermSize=512m
CATALINA_OPTS
-Dactivemq.conf=C:/dev/appConfig/app-common-config/environment/dev/activemq
-Dactivemq.data=C:/dev/appConfig/activemq-data
-Dlog4j.configuration=file:C:/dev/appConfig/logging/log4j.xml
-Djava.security.auth.login.config=C:/apache-tomcat-7.0.42/conf/jaas.config
远程Tomcat运行配置:
JMX 端口:11444 远程暂存:相同的文件系统 主机:相同的文件系统
远程连接主机: localhost 远程连接端口:8080
部署: my-web:war
catalina.properties
## JMS Connection Factory
JMS.connectionFactory.factoryName=jms/jms.connectionFactory
JMS.connectionFactory.auth=Container
JMS.connectionFactory.brokerName=ActiveMQBroker
JMS.connectionFactory.brokerURL=tcp://localhost:61616
JMS.connectionFactory.factory=org.apache.activemq.jndi.JNDIReferenceFactory
JMS.connectionFactory.type=org.apache.activemq.ActiveMQConnectionFactory
JMS.connectionFactory.typeInterface=javax.jms.ConnectionFactory
## Local JMS Queue
JMS.queue.auth=Container
JMS.queue.name=jms/my.queue
JMS.queue.physicalName=my.queue
JMS.queue.factory=org.apache.activemq.jndi.JNDIReferenceFactory
JMS.queue.type=org.apache.activemq.command.ActiveMQQueue
context.xml
<ResourceLink global="${JMS.connectionFactory.factoryName}" name="${JMS.connectionFactory.factoryName}" type="${JMS.connectionFactory.typeInterface}"/>
<ResourceLink global="${JMS.queue.name}" name="${JMS.queue.name}" />
server.xml
<Resource auth="${JMS.connectionFactory.auth}"
brokerName="${JMS.connectionFactory.brokerName}" brokerURL="${JMS.connectionFactory.brokerURL}"
description="JMS Connection Factory" factory="${JMS.connectionFactory.factory}"
name="${JMS.connectionFactory.factoryName}" type="${JMS.connectionFactory.type}" />
<Resource auth="${JMS.queue.auth}" description="Outbound Queue"
factory="${JMS.queue.factory}" name="${JMS.queue.name}"
physicalName="${JMS.queue.physicalName}" type="${JMS.queue.type}" />
localhost:8080/manager/text/resources
OK - Listed global resources of all types
jms/jms.connectionFactory:org.apache.activemq.ActiveMQConnectionFactory
jms/my.queue:org.apache.activemq.command.ActiveMQQueue
UserDatabase:org.apache.catalina.users.MemoryUserDatabase
JNDI 查找
@Bean(name = {"jndiObjectFactory"})
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
@Profile("default")
public JndiObjectFactoryBean jndiObjectFactory() {
JndiObjectFactoryBean jof = new JndiObjectFactoryBean();
jof.setResourceRef(true);
jof.setJndiName("jms.connectionFactory");
Properties jndiProps = new Properties();
jndiProps.put("java.naming.factory.initial", "org.apache.naming.java.javaURLContextFactory");
jof.setJndiEnvironment(jndiProps);
return jof;
}
错误
SEVERE: Exception sending context initialized event to listener instance of class
org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'TestController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.me.test.factory.TestFactory com.me.test.tester.web.controller.TestController.testFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'TestFactory': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jndiObjectFactory' defined in class path resource [com/me/test/SpringConfig.class]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [jms.connectionFactory] is not bound in this Context. Unable to find [jms.connectionFactory].
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633)
at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1551)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:622)
at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:569)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:301)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819)
at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1487)
at javax.management.remote.rmi.RMIConnectionImpl.access0(RMIConnectionImpl.java:97)
at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1328)
at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1420)
at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:848)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322)
at sun.rmi.transport.Transport.run(Transport.java:177)
at sun.rmi.transport.Transport.run(Transport.java:174)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:173)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:556)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:811)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:670)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.me.test.factory.TestFactory com.me.test.tester.web.controller.TestController.testFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'TestFactory': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jndiObjectFactory' defined in class path resource [com/me/test/SpringConfig.class]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [jms.connectionFactory] is not bound in this Context. Unable to find [jms.connectionFactory].
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:508)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
... 56 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'TestFactory': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jndiObjectFactory' defined in class path resource [com/me/test/SpringConfig.class]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [jms.connectionFactory] is not bound in this Context. Unable to find [jms.connectionFactory].
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:136)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:407)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1017)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:960)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:858)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480)
... 58 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jndiObjectFactory' defined in class path resource [com/me/test/SpringConfig.class]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: Name [jms.connectionFactory] is not bound in this Context. Unable to find [jms.connectionFactory].
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:323)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:205)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:991)
at com.me.test.factory.TestQueueFactory.newInstance(TestQueueFactory.java:45)
at com.me.test.factory.TestFactory.createEmitter(TestFactory.java:178)
at com.me.test.factory.TestFactory.readConfigurationFromPropertiesFile(TestFactory.java:155)
at com.me.test.factory.TestFactory.init(TestFactory.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:349)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:300)
at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:133)
... 70 more
Caused by: javax.naming.NameNotFoundException: Name [jms.connectionFactory] is not bound in this Context. Unable to find [jms.connectionFactory].
at org.apache.naming.NamingContext.lookup(NamingContext.java:820)
at org.apache.naming.NamingContext.lookup(NamingContext.java:168)
at org.apache.naming.SelectorContext.lookup(SelectorContext.java:158)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at org.springframework.jndi.JndiTemplate.doInContext(JndiTemplate.java:155)
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:179)
at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:104)
at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:106)
at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:231)
at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:217)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549)
... 86 more
这只是我的一个愚蠢错误,我不确定为什么它以前作为本地 tomcat 运行 配置工作。我回去尝试那样做,但我得到了同样的错误。
这仅仅是因为当我试图查找时 JNDI 名称应该是 "jms/jms.connectionFactory" "jms.connectionFactory"。