所以我使用Spring在我的本地机器上开发了一个webapp,它在本地工作得很好。然后我尝试部署它,并将.war文件上传到我的网站。
我得到NoClassDefFoundError,这是堆栈跟踪
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'commonController' defined in file [/usr/local/shared/tomcat/kenendz/webapps/zzz/WEB-INF/classes/zzz/web/CommonController.class]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.aspectj.weaver.reflect.ReflectionWorld
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:664)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:630)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:678)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:549)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:490)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
at javax.servlet.GenericServlet.init(GenericServlet.java:160)
at sun.reflect.GeneratedMethodAccessor62.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:274)
at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:271)
at java.security.AccessController.doPrivileged(Native Method)
at javax.security.auth.Subject.doAsPrivileged(Subject.java:536)
at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:306)
at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:166)
at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:120)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1260)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1185)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:857)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:135)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:307)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.aspectj.weaver.reflect.ReflectionWorld
at org.aspectj.weaver.tools.PointcutParser.setClassLoader(PointcutParser.java:219)
at org.aspectj.weaver.tools.PointcutParser.<init>(PointcutParser.java:205)
at org.aspectj.weaver.tools.PointcutParser.getPointcutParserSupportingSpecifiedPrimitivesAndUsingSpecifiedClassLoaderForResolution(PointcutParser.java:167)
at org.springframework.aop.aspectj.AspectJExpressionPointcut.initializePointcutParser(AspectJExpressionPointcut.java:216)
at org.springframework.aop.aspectj.AspectJExpressionPointcut.buildPointcutExpression(AspectJExpressionPointcut.java:201)
at org.springframework.aop.aspectj.AspectJExpressionPointcut.checkReadyToMatch(AspectJExpressionPointcut.java:193)
at org.springframework.aop.aspectj.AspectJExpressionPointcut.getClassFilter(AspectJExpressionPointcut.java:170)
at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:208)
at org.springframework.aop.support.AopUtils.canApply(AopUtils.java:262)
at org.springframework.aop.support.AopUtils.findAdvisorsThatCanApply(AopUtils.java:294)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findAdvisorsThatCanApply(AbstractAdvisorAutoProxyCreator.java:118)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:88)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:69)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:330)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:293)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:422)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
... 42 more
我的classpath中有aspectjweaver.jar和aspectjrt.jar,webapp可以在我的本地系统上运行。
更新
我发现在部署此Web应用程序时存在权限问题
INFO: Caught AccessControlException when accessing system property [spring.liveBeansView.mbeanDomain]; its value will be returned [null]. Reason: access denied ("java.util.PropertyPermission" "spring.liveBeansView.mbeanDomain" "read")
Aug 23, 2015 11:39:57 AM org.springframework.web.context.support.StandardServletEnvironment getSystemAttribute
INFO: Caught AccessControlException when accessing system environment variable [spring.liveBeansView.mbeanDomain]; its value will be returned [null]. Reason: access denied ("java.lang.RuntimePermission" "getenv.spring.liveBeansView.mbeanDomain")
Aug 23, 2015 11:39:57 AM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 1382 ms
Aug 23, 2015 11:39:57 AM org.springframework.web.servlet.DispatcherServlet initServletBean
INFO: FrameworkServlet 'servlet': initialization started
Aug 23, 2015 11:39:57 AM org.springframework.web.context.support.StandardServletEnvironment getSystemAttribute
INFO: Caught AccessControlException when accessing system property [spring.profiles.active]; its value will be returned [null]. Reason: access denied ("java.util.PropertyPermission" "spring.profiles.active" "read")
Aug 23, 2015 11:39:57 AM org.springframework.web.context.support.StandardServletEnvironment getSystemAttribute
INFO: Caught AccessControlException when accessing system environment variable [spring.profiles.active]; its value will be returned [null]. Reason: access denied ("java.lang.RuntimePermission" "getenv.spring.profiles.active")
Aug 23, 2015 11:39:57 AM org.springframework.web.context.support.StandardServletEnvironment getSystemAttribute
INFO: Caught AccessControlException when accessing system property [spring.profiles.default]; its value will be returned [null]. Reason: access denied ("java.util.PropertyPermission" "spring.profiles.default" "read")
Aug 23, 2015 11:39:57 AM org.springframework.web.context.support.StandardServletEnvironment getSystemAttribute
INFO: Caught AccessControlException when accessing system environment variable [spring.profiles.default]; its value will be returned [null]. Reason: access denied ("java.lang.RuntimePermission" "getenv.spring.profiles.default")
Aug 23, 2015 11:39:57 AM org.springframework.web.context.support.StandardServletEnvironment getSystemAttribute
INFO: Caught AccessControlException when accessing system property [spring.profiles.default]; its value will be returned [null]. Reason: access denied ("java.util.PropertyPermission" "spring.profiles.default" "read")
Aug 23, 2015 11:39:57 AM org.springframework.web.context.support.StandardServletEnvironment getSystemAttribute
INFO: Caught AccessControlException when accessing system environment variable [spring.profiles.default]; its value will be returned [null]. Reason: access denied ("java.lang.RuntimePermission" "getenv.spring.profiles.default")
答案 0 :(得分:0)
我认为这是请求的问题,但是Evil Toad的问题让我检查webapp是否已成功部署。结果证明这是安全问题
这是tomcat生成的catalina日志
INFO: Caught AccessControlException when accessing system property [spring.profiles.active]; its value will be returned [null]. Reason: access denied ("java.util.PropertyPermission" "spring.profiles.active" "read")
Aug 23, 2015 11:29:59 AM org.springframework.web.context.support.StandardServletEnvironment getSystemAttribute
INFO: Caught AccessControlException when accessing system environment variable [spring.profiles.active]; its value will be returned [null]. Reason: access denied ("java.lang.RuntimePermission" "getenv.spring.profiles.active")
Aug 23, 2015 11:29:59 AM org.springframework.web.context.support.StandardServletEnvironment getSystemAttribute
INFO: Caught AccessControlException when accessing system property [spring.profiles.default]; its value will be returned [null]. Reason: access denied ("java.util.PropertyPermission" "spring.profiles.default" "read")
Aug 23, 2015 11:29:59 AM org.springframework.web.context.support.StandardServletEnvironment getSystemAttribute
INFO: Caught AccessControlException when accessing system environment variable [spring.profiles.default]; its value will be returned [null]. Reason: access denied ("java.lang.RuntimePermission" "getenv.spring.profiles.default")
Aug 23, 2015 11:29:59 AM org.springframework.web.context.support.StandardServletEnvironment getSystemAttribute
INFO: Caught AccessControlException when accessing system property [spring.profiles.default]; its value will be returned [null]. Reason: access denied ("java.util.PropertyPermission" "spring.profiles.default" "read")
Aug 23, 2015 11:29:59 AM org.springframework.web.context.support.StandardServletEnvironment getSystemAttribute
INFO: Caught AccessControlException when accessing system environment variable [spring.profiles.default]; its value will be returned [null]. Reason: access denied ("java.lang.RuntimePermission" "getenv.spring.profiles.default")
所以我修改了catalina.policy 添加了以下行
grant codeBase "file:${catalina.base}/webapps/webAppName/-" {
permission java.security.AllPermission;
};
webAppName应替换为webapp的名称
最后,webapp已成功部署,并且可以正常运行!!