使用javax.naming.NameNotFoundException部署到Weblogic

时间:2023-01-19 22:04:07

We are trying to successfully deploy a Spring 3.2.6 application that was developed on Tomcat 6 to Weblogic 12.1.2. The application works fine in Tomcat. The application is calling the Mail Connection Service on 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 6上开发的Spring 3.2.6应用程序成功部署到Weblogic 12.1.2。该应用程序在Tomcat中运行良好。应用程序在Tomcat上调用邮件连接服务(mail-1.4.7.jar)。在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

1 个解决方案

#1


0  

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

#1


0  

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