我们的项目在Jetty服务器上并完全工作,然后这个项目部署在Jboss 7服务器上,但是有一些错误。
我制作war文件并在E:\jboss-as-7.1.1.Final\standalone\deployments
文件夹中复制并过去并自动部署成为启动并发出此错误:
java.lang.NoClassDefFoundError: javax/mail/internet/AddressException
但在\WEB-INF\lib
我有mail.jar文件..
那么如何删除此错误?
细节错误:
15:34:02,245 ERROR [org.springframework.web.context.ContextLoader] (MSC service thread 1-4) Context initialization failed: org.springframework.beans.factor
y.BeanCreationException: Error creating bean with name 'log4jInitialization' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocati
on of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/mail/internet/AddressException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420) [org.s
pringframework.beans-3.1.0.M1.jar:3.1.0.M1]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) [org.spri
ngframework.beans-3.1.0.M1.jar:3.1.0.M1]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) [org.spring
framework.beans-3.1.0.M1.jar:3.1.0.M1]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295) [org.springframework.beans-3.1.0.M1.jar:
3.1.0.M1]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) [org.springframework.
beans-3.1.0.M1.jar:3.1.0.M1]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292) [org.springframework.beans-3.1.0.M1.jar:3.
1.0.M1]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) [org.springframework.beans-3.1.0.M1.jar:3.1.
0.M1]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563) [org.springfr
amework.beans-3.1.0.M1.jar:3.1.0.M1]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:900) [org.springf
ramework.context-3.1.0.M1.jar:3.1.0.M1]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:455) [org.springframework.context-3.1.0.M
1.jar:3.1.0.M1]
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:294) [org.springframework.web-3.1.0.M1.jar:3.1.0.M1
]
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:215) [org.springframework.web-3.1.0.M1.jar:3.1.0.M1]
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47) [org.springframework.web-3.1.0.M1.jar:3.
1.0.M1]
at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0_01]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0_01]
at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_01]
Caused by: java.lang.NoClassDefFoundError: javax/mail/internet/AddressException
at java.lang.Class.getDeclaredConstructors0(Native Method) [rt.jar:1.7.0_01]
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2404) [rt.jar:1.7.0_01]
at java.lang.Class.getConstructor0(Class.java:2714) [rt.jar:1.7.0_01]
at java.lang.Class.newInstance0(Class.java:343) [rt.jar:1.7.0_01]
at java.lang.Class.newInstance(Class.java:325) [rt.jar:1.7.0_01]
at org.apache.log4j.helpers.OptionConverter.instantiateByClassName(OptionConverter.java:336) [log4j-1.2.16.jar:]
at org.apache.log4j.helpers.OptionConverter.instantiateByKey(OptionConverter.java:123) [log4j-1.2.16.jar:]
at org.apache.log4j.PropertyConfigurator.parseAppender(PropertyConfigurator.java:752) [log4j-1.2.16.jar:]
at org.apache.log4j.PropertyConfigurator.parseCategory(PropertyConfigurator.java:735) [log4j-1.2.16.jar:]
at org.apache.log4j.PropertyConfigurator.configureRootCategory(PropertyConfigurator.java:615) [log4j-1.2.16.jar:]
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:502) [log4j-1.2.16.jar:]
at org.apache.log4j.PropertyConfigurator.doConfigure(PropertyConfigurator.java:547) [log4j-1.2.16.jar:]
at org.apache.log4j.PropertyConfigurator.configure(PropertyConfigurator.java:415) [log4j-1.2.16.jar:]
at org.springframework.util.Log4jConfigurer.initLogging(Log4jConfigurer.java:72) [org.springframework.core-3.1.0.M1.jar:3.1.0.M1]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.7.0_01]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) [rt.jar:1.7.0_01]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_01]
at java.lang.reflect.Method.invoke(Method.java:601) [rt.jar:1.7.0_01]
at org.springframework.util.MethodInvoker.invoke(MethodInvoker.java:273) [org.springframework.core-3.1.0.M1.jar:3.1.0.M1]
at org.springframework.beans.factory.config.MethodInvokingFactoryBean.doInvoke(MethodInvokingFactoryBean.java:162) [org.springframework.beans-3.1.0
.M1.jar:3.1.0.M1]
at org.springframework.beans.factory.config.MethodInvokingFactoryBean.afterPropertiesSet(MethodInvokingFactoryBean.java:152) [org.springframework.b
eans-3.1.0.M1.jar:3.1.0.M1]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1479) [or
g.springframework.beans-3.1.0.M1.jar:3.1.0.M1]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417) [org.s
pringframework.beans-3.1.0.M1.jar:3.1.0.M1]
... 20 more
Caused by: java.lang.ClassNotFoundException: javax.mail.internet.AddressException from [Module "org.apache.log4j:main" from local module loader @1da817b (r
oots: E:\jboss-as-7.1.1.Final\modules)]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
... 43 more
请帮忙,如何删除此错误?
谢谢,
卡姆利什
答案 0 :(得分:3)
JBoss AS 7带有隔离的类加载,因此您应该仔细配置项目依赖项。详细信息为here。
在你的情况下,我看到Spring引用了由JBossAS提供的Log4j:Module "org.apache.log4j:main"
,并尝试将其配置为执行异常操作(可能尝试通过电子邮件进行日志记录)。问题是log4j模块无法访问mail-api,所以它会抱怨。
现在您至少有3个解决方案:
让Spring只使用log4j而不尝试配置它。而是在app-server级别配置log4j。见this。询问Spring专家如何做到这一点:)
将log4j.jar放入/ WEB-INF / lib中,不要将Module "org.apache.log4j"
公开给您的网络应用程序。
将mail-api暴露给log4j模块并从你的应用程序中删除/WEB-INF/lib/mail.jar。您必须编辑jboss-as-7.1.1.Final/modules/org/apache/log4j/main/module.xml
以包含对mail-api的依赖:
<dependencies>
<module name="org.dom4j" optional="true"/>
<module name="javax.api"/>
<module name="javax.mail.api" export="true"/>
</dependencies>