我们正在尝试将在 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
感谢进阶!
汤姆
最佳答案
我必须在 Weblogic 中设置邮件资源,还必须更改配置文件以反射(reflect) Weblogic 服务器中邮件 session 的新 JNDI 资源。
来自 mailSession.JndiName=java:comp/env/mail/xxxx 到 mailSession.JndiName=邮件/xxxx
谢谢,
汤姆
关于java - 使用 javax.naming.NameNotFoundException 部署到 Weblogic,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25794158/