I am using IntelliJ IDEA 14.0.2 to launch a local Tomcat 7.0.42 instance and then to separately deploy a WAR using a remote Tomcat run configuration. My web app fails to acquire a resource through JNDI and I suspect it is because it fails to remotely connect to JMX, although the WAR is deploying without issues if I comment out the JNDI lookup. If I include the Tomcat launch and WAR deployment in the same local Tomcat run configuration, the lookup works fine.
我使用IntelliJ IDEA 14.0.2启动本地Tomcat 7.0.42实例,然后使用远程Tomcat运行配置单独部署WAR。我的Web应用程序无法通过JNDI获取资源,我怀疑这是因为它无法远程连接到JMX,尽管如果我注释掉JNDI查找,WAR正在部署而没有问题。如果我在相同的本地Tomcat运行配置中包含Tomcat启动和WAR部署,则查找工作正常。
Here are all the details that I think are relevant, please let me know if you want anything else. Thanks for your help!
以下是我认为相关的所有细节,如果您还有其他需要,请告诉我。谢谢你的帮助!
Local Tomcat Run Configuration:
HTTP port: 8080
HTTP端口:8080
JMX port: 11444
JMX端口:11444
JAVA_OPTS
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
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
Remote Tomcat Run Configuration:
JMX port: 11444 Remote staging: Same file system Host: Same file system
JMX端口:11444远程登台:相同的文件系统主机:相同的文件系统
Remote Connection Host: localhost Remote Connection Port: 8080
远程连接主机:localhost远程连接端口:8080
Deployment: my-web:war
部署: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 lookup
@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;
}
The error
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$1.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.access$300(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$1.run(Transport.java:177)
at sun.rmi.transport.Transport$1.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$1.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$1.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
1 个解决方案
#1
0
It was just a dumb mistake on my part and I'm not sure why it was working as a local tomcat run configuration before. I went back to trying it that way and I got the same error.
这只是我的一个愚蠢的错误,我不知道为什么它之前作为本地tomcat运行配置工作。我回去尝试那样,我得到了同样的错误。
It was simply because the JNDI name should be "jms/jms.connectionFactory" when I was trying to lookup just "jms.connectionFactory".
这只是因为当我试图查找“jms.connectionFactory”时,JNDI名称应为“jms / jms.connectionFactory”。
#1
0
It was just a dumb mistake on my part and I'm not sure why it was working as a local tomcat run configuration before. I went back to trying it that way and I got the same error.
这只是我的一个愚蠢的错误,我不知道为什么它之前作为本地tomcat运行配置工作。我回去尝试那样,我得到了同样的错误。
It was simply because the JNDI name should be "jms/jms.connectionFactory" when I was trying to lookup just "jms.connectionFactory".
这只是因为当我试图查找“jms.connectionFactory”时,JNDI名称应为“jms / jms.connectionFactory”。