Error creating bean with name '***' defined in URL
2017-04-17 09:56
816 查看
我在spring-mvc.xml中配置了<context:component-scan base-package="com.beta.zjw"/>自动装配bean,然后在spring-context-shiro.xml中使用这些bean。
在启动时报错:
Error creating bean with name 'shiroFilter' defined in URL [file:spring-context-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 URL [file:spring-context-shiro.xml]: Cannot resolve reference to bean 'systemAuthorizingRealm' while setting bean property 'realm'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No bean named 'systemAuthorizingRealm' available
根据web.xml的配置:
spring-mvc.xml与spring-context-shiro.xml从属于不同容器。
所以,虽然在spring-mvc.xml中配置了自动扫描注入,但在spring-context-shiro.xml这个容器中,这些bean name是不存在的。
在spring-context-shiro.xml配置对需要使用的包com.beta.zjw.shiro自动扫描注入:
我们一般使用这种方法获取配置文件:
ClassPathXmlApplicationContext re = new ClassPathXmlApplicationContext("applicationContext.xml");
而由spring自动装配的xml文件,根据web.xml的配置:
<param-name>contextConfigLocation</param-name>虽然spring-mybatis.xml、spring-context-shiro.xml和spring-mvc.xml配置的是同一个param-name,
但spring-mvc.xml的param-name属于servlet类springMVC:
<servlet-name>springMVC</servlet-name>所以在springMVC以外,是拿不到在spring-mvc.xml中配置的自动注入的。
在启动时报错:
Error creating bean with name 'shiroFilter' defined in URL [file:spring-context-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 URL [file:spring-context-shiro.xml]: Cannot resolve reference to bean 'systemAuthorizingRealm' while setting bean property 'realm'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No bean named 'systemAuthorizingRealm' available
根据web.xml的配置:
<context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath*:/spring-mybatis*.xml classpath*:/spring-context-shiro.xml </param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>springMVC</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath*:/spring-mvc*.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>springMVC</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping>
spring-mvc.xml与spring-context-shiro.xml从属于不同容器。
所以,虽然在spring-mvc.xml中配置了自动扫描注入,但在spring-context-shiro.xml这个容器中,这些bean name是不存在的。
在spring-context-shiro.xml配置对需要使用的包com.beta.zjw.shiro自动扫描注入:
<context:component-scan base-package="com.beat.zjw.shiro"/>问题解决。
我们一般使用这种方法获取配置文件:
ClassPathXmlApplicationContext re = new ClassPathXmlApplicationContext("applicationContext.xml");
而由spring自动装配的xml文件,根据web.xml的配置:
<param-name>contextConfigLocation</param-name>虽然spring-mybatis.xml、spring-context-shiro.xml和spring-mvc.xml配置的是同一个param-name,
但spring-mvc.xml的param-name属于servlet类springMVC:
<servlet-name>springMVC</servlet-name>所以在springMVC以外,是拿不到在spring-mvc.xml中配置的自动注入的。
相关文章推荐
- Error creating bean with name 'dataSource' defined in URL
- Error creating bean with name 'simpleUrlHandlerMapping' defined in ServletContext resource [/WEB-IN
- Error creating bean with name '****' defined in file [url]: Invocation of init method failed;
- Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]: Initialization of bean faile
- Error creating bean with name 'sessionFactory' defined in ServletContext resource
- Error creating bean with name 'sessionFactory' defined in file
- Error creating bean with name 'StuService' defined in ServletContext resource [/WEB-INF/applicationC
- Error creating bean with name 'cxf' defined in class path resource [META-INF/cxf/cxf.xml]
- Error creating bean with name 'mySessionFactory' defined in class path resource [applicationContext.xml]:
- Spring异常:Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF
- Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xm
- SSH架构易出现的问题之Error creating bean with name '*' defined in file [*.xml]
- Spring异常:Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/classes/applicationContext.
- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'selectcommoninfo' defined in ServletCont
- Spring异常:Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/classes/applicationContext.
- 异常:org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletCo
- Error creating bean with name 'dwrSysuserDao' defined in ServletContext resource
- Spring Error creating bean with name 'sessionFactory ' defined in ServletContext resource [/WEB-INF/
- Error creating bean with name 'sessionFactory' defined in ServletContext resource
- Bug--Error creating bean with name 'sessionFactory' defined in class path resource [data_context.xml