问题描述
我的web.xml信息是 <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/dataAccessContext.xml,/WEB-INF/applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>MainServlet</servlet-name> <servlet-class>com.test.framework.web.servlet.MainServlet</servlet-class> <load-on-startup>4</load-on-startup> </servlet>我是想 MainServlet-servlet.xml引用applicationContext.xml内的bean.就报出org.springframework.beans.factory.BeanCreationException: Error creating bean with name '/Logon.do' defined in ServletContext resource [/WEB-INF/MainServlet-servlet.xml]: Cannot resolve reference to bean 'LogonBizLogic' while setting bean property 'bizLogic'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'LogonBizLogic' is definedCaused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'LogonBizLogic' is definedat org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:360)at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedBeanDefinition(AbstractBeanFactory.java:914)at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:241)at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:267)at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:110)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1100)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:862)at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:423)at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:249)at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:155)at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:246)at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:160)at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:291)at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:352)at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:332)at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:266)at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:236)at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:126)我错在哪里呀 问题补充:Wind_ZhongGang 写道
解决方案
那这是服务器的差异造成的,我看到这上面很多人都说使用Weblogic有各种各样的错误,但在Tomcat上却好好的,去搜索下,看看这两者的区别吧。
解决方案二:
Spring web MVC servlet that dispatches requests to registered handlers. - Has its own application context, by default defined in "{servlet-name}-servlet.xml", - i.e. "petstore-servlet.xml" in this case. 你从这得出的那个结论?那你的MainServlet做的什么事情?默认配置?那配置在哪的?
解决方案三:
MainServlet-servlet.xml 那我没看到你在哪个地方导入过这个配置文件呢
解决方案四:
MainServlet-servlet.xml 是dispatcherServlet?那你应该在web.xml里配置DispatcherSevlet 如下例:<servlet> <servlet-name>dreamServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/config/dream-servlet.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dreamServlet</servlet-name> <url-pattern>*.z</url-pattern> </servlet-mapping>并且如果你要使用ApplicationContext中定义的bean,还需要在DispatcherServelt.xml中引入。
解决方案五:
MainServlet-servlet.xml 这也是Spring配置文件?如果是的话,在contextConfigLocation中也加入这个文件,并且MainServlet-servlet.xml中引入<import resource="application-context.xml"/>