使用javax.naming.NameNotFoundException部署到Weblogic

时间:2014-09-11 17:59:59

标签: java spring email tomcat weblogic12c

我们正在尝试将在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文件夹中。

这是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>

属性文件内容为:

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

当我们运行部署时,我们在日志中看到以下异常:

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)

我查看了Weblogic中的JNDI树,并且没有名为'comp / env / mail / xxx'的资源。

我们是否只需要在Weblogic上配置JavaMail,如:http://docs.oracle.com/cd/E15586_01/apirefs.1111/e13952/taskhelp/mail/CreateMailSessions.html

感谢高级!

汤姆

1 个答案:

答案 0 :(得分:0)

我必须在Weblogic中设置邮件资源,同样必须更改配置文件以反映Weblogic服务器中邮件会话的新JNDI资源。

从 mailSession.JndiName =的java:comp / env的/邮件/ XXXX 至 mailSession.JndiName =邮件/ XXXX

谢谢,

汤姆