简体   繁体   English

使用javax.naming.NameNotFoundException部署到Weblogic

[英]Deploying to Weblogic with javax.naming.NameNotFoundException

We are trying to successfully deploy a Spring 3.2.6 application that was developed on Tomcat 6 to Weblogic 12.1.2. 我们正在尝试将在Tomcat 6上开发的Spring 3.2.6应用程序成功部署到Weblogic 12.1.2。 The application works fine in Tomcat. 该应用程序在Tomcat中运行良好。 The application is calling the Mail Connection Service on Tomcat (mail-1.4.7.jar). 该应用程序正在Tomcat上调用邮件连接服务(mail-1.4.7.jar)。 On Tomcat the library(mail jar) resides in the tomcat/lib and in Weblogic we put it in app/oracle/admin/domains/devtest_domain/lib folder. 在Tomcat上,库(邮件jar)位于tomcat / lib中,而在Weblogic中,我们将其放在app / oracle / admin / domains / devtest_domain / lib文件夹中。

This is the applicationContext.xml: 这是applicationContext.xml:

<!-- Data Source using JNDI -->
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="resourceRef">
        <value>true</value>
    </property>
    <property name="jndiName">
        <value>${datasource.JndiName.DS}</value>
    </property>
</bean>
<bean id="mailService" class="com.xxxx.xxxx.utils.MailService">
    <property name="mailSender" ref="mailSender" />
</bean>

<bean id="mailSender"
      class="org.springframework.mail.javamail.JavaMailSenderImpl">
    <property name="session" ref="mailSession" />
</bean>

<!-- Mail Session using JNDI -->
<bean id="mailSession" class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="resourceRef">
        <value>true</value>
    </property>
    <property name="jndiName">
        <value>${mailSession.JndiName}</value>
    </property>
</bean>

The property file contents are: 该属性文件的内容为:

#Datasource
datasource.JndiName.DS=java:comp/env/jdbc/xxxx
#MailSession
mailSession.JndiName=java:comp/env/mail/xxxx    

When we run the deployment we see the following exception in the log: 运行部署时,我们在日志中看到以下异常:

SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'forgotPasswordAction': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.xxx.xxxx.utils.MailService com.xx.xx.action.ForgotPasswordAction.mailService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mailService' defined in file [/u01/app/oracle/admin/domains/devtest_domain/servers/WLS_DEV1/stage/xx-dev/xxx-dev/WEB-INF/classes/META-INF/spring/applicationContext.xml]: Cannot resolve reference to bean 'mailSender' while setting bean property 'mailSender'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mailSender' defined in file [/u01/app/oracle/admin/domains/devtest_domain/servers/WLS_DEV1/stage/xx-dev/xx-dev/WEB-INF/classes/META-INF/spring/applicationContext.xml]: Cannot resolve reference to bean 'mailSession' while setting bean property 'session'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mailSession' defined in file 
[/u01/app/oracle/admin/domains/devtest_domain/servers/WLS_DEV1/stage/xxx-dev/xxxx-dev/WEB-INF/classes/META-INF/spring/applicationContext.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: While trying to look up comp/env/mail/xxxin /app/webapp/xxx-dev/1749454341.; remaining name 'comp/env/mail/xxx'
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mailSession' defined in file [/u01/app/oracle/admin/domains/devtest_domain/servers/WLS_DEV1/stage/xxxx-dev/xxxx-dev/WEB-INF/classes/META-INF/spring/applicationContext.xml]: Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: While trying to look up comp/env/mail/xxin /app/webapp/xxx-dev/1749454341.; remaining name 'comp/env/mail/xxx'
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1146)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
        at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)

I looked at the JNDI tree in Weblogic and no resource by the name 'comp/env/mail/xxx' exists. 我查看了Weblogic中的JNDI树,没有名称为'comp / env / mail / xxx'的资源。

Do we just need to configure JavaMail on the Weblogic like : http://docs.oracle.com/cd/E15586_01/apirefs.1111/e13952/taskhelp/mail/CreateMailSessions.html 我们是否只需要在Weblogic上配置JavaMail,例如: http : //docs.oracle.com/cd/E15586_01/apirefs.1111/e13952/taskhelp/mail/CreateMailSessions.html

Thanks in Advanced! 提前致谢!

Tom 汤姆

I had to setup the mail resource in Weblogic, also the configuration file had to change to reflect the new JNDI resource for mail sessions in the Weblogic server too. 我必须在Weblogic中设置邮件资源,还必须更改配置文件以反映Weblogic服务器中用于邮件会话的新JNDI资源。

From mailSession.JndiName=java:comp/env/mail/xxxx To mailSession.JndiName=mail/xxxx 从mailSession.JndiName = java:comp / env / mail / xxxx到mailSession.JndiName = mail / xxxx

Thanks, 谢谢,

Tom 汤姆

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM