修改包名后启动TomCat报错,新手上路,望大佬们不吝赐教

修改包名后启动TomCat报错,新手上路,望大佬们不吝赐教

问题描述:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'shiroFilter' defined in class path resource [spring-config-shiro.xml]: Cannot resolve reference to bean 'securityManager' while setting bean property 'securityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityManager' defined in class path resource [spring-config-shiro.xml]: Cannot resolve reference to bean 'userRealm' while setting bean property 'realm'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRealm': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.wangxin.flow.modules.sys.service.IUserService com.wangxin.flow.modules.sys.security.shiro.realm.UserRealm.userService; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.wamgxin.flow.core.security.shiro.cache.SpringCacheManagerWrapper] for bean with name 'shiroCacheManager' defined in class path resource [spring-config-shiro.xml]; nested exception is java.lang.ClassNotFoundException: com.wamgxin.flow.core.security.shiro.cache.SpringCacheManagerWrapper
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:336)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1456)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200)
at org.springframework.context.support.PostProcessorRegistrationDelegate.registerBeanPostProcessors(PostProcessorRegistrationDelegate.java:232)
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:618)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:467)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4738)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5158)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1387)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1377)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityManager' defined in class path resource [spring-config-shiro.xml]: Cannot resolve reference to bean 'userRealm' while setting bean property 'realm'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRealm': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.wangxin.flow.modules.sys.service.IUserService com.wangxin.flow.modules.sys.security.shiro.realm.UserRealm.userService; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.wamgxin.flow.core.security.shiro.cache.SpringCacheManagerWrapper] for bean with name 'shiroCacheManager' defined in class path resource [spring-config-shiro.xml]; nested exception is java.lang.ClassNotFoundException: com.wamgxin.flow.core.security.shiro.cache.SpringCacheManagerWrapper
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:336)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1456)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
... 24 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRealm': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.wangxin.flow.modules.sys.service.IUserService com.wangxin.flow.modules.sys.security.shiro.realm.UserRealm.userService; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.wamgxin.flow.core.security.shiro.cache.SpringCacheManagerWrapper] for bean with name 'shiroCacheManager' defined in class path resource [spring-config-shiro.xml]; nested exception is java.lang.ClassNotFoundException: com.wamgxin.flow.core.security.shiro.cache.SpringCacheManagerWrapper
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
... 34 more
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.wangxin.flow.modules.sys.service.IUserService com.wangxin.flow.modules.sys.security.shiro.realm.UserRealm.userService; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [com.wamgxin.flow.core.security.shiro.cache.SpringCacheManagerWrapper] for bean with name 'shiroCacheManager' defined in class path resource [spring-config-shiro.xml]; nested exception is java.lang.ClassNotFoundException: com.wamgxin.flow.core.security.shiro.cache.SpringCacheManagerWrapper
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:508)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
... 42 more

spring-config-shiro.xml 在祖册securityManager,userRealm的 realm等等bean的时候找不到对应的文件,包名改了以后没改class的位置,用原来的包名搜索,替换成新的包名

ClassNotFoundException 异常 检查你的注解 和Bean扫描器

  nested exception is java.lang.ClassNotFoundException: com.wamgxin.flow.core.security.shiro.cache.SpringCacheManagerWrapper

确定该路径下有这个类吗,还有xml里面的配置的包名.类名改了没有

ClassNotFoundException: com.wamgxin.flow.core.security.shiro.cache.SpringCacheManagerWrapper
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:336)

首先你修改之后代码没问题,然后看运行抛出什么异常,根据你的异常信息,应该是没有注册进去你的bean没有注入的所以找不到该bean,也有可能是缓存的问题,你重新build一下项目 没准就好了。。。

在修改包名之前是好的,可以运行,不报错不抛异常,所以我觉得代码是没有问题的,问题出在修改了包名之后,某些地方不匹配了。不知道是不是这样,还望各位大佬指点

修改包名之后,路径会变,你检查下你的context.xml里面是不是配置了特定的路径。

说错了,你看下server.xml里面是不是有这种配置,删掉在试试。

  <Context docBase="D:\project\weixin" path="/" reloadable="true" source="org.eclipse.jst.jee.server:bix-wxstatis-deploy"/>