-
Spring的配置异常5
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Servlet.init() for servlet annomvc threw exception
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:851)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:278)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)
root cause
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private pro.login.service.UserService pro.login.controller.loginController.userService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [pro.login.service.UserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
javax.servlet.GenericServlet.init(GenericServlet.java:160)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:851)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:278)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)
root cause
org.springframework.beans.factory.BeanCreationException: Could not autowire field: private pro.login.service.UserService pro.login.controller.loginController.userService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [pro.login.service.UserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:507)
org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:283)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
javax.servlet.GenericServlet.init(GenericServlet.java:160)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:851)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:278)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)
root cause
org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [pro.login.service.UserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:920)
org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:789)
org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:283)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
javax.servlet.GenericServlet.init(GenericServlet.java:160)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:851)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:278)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.19 logs.
--------------------------------------------------------------------------------
Apache Tomcat/7.0.19
我的配置
<!-- ①:对web包中的所有类进行扫描,以完成Bean创建和自动依赖注入的功能 -->
<context:component-scan base-package="pro.login.controller"/>
<context:component-scan base-package="pro.login.service"/>
<context:component-scan base-package="pro.login.dao"/>
<!-- ②:启动Spring MVC的注解功能,完成请求和注解POJO的映射 -->
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
<!-- ③:对模型视图名称的解析,即在模型视图名称添加前后缀 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/WEB-INF/jsp/" p:suffix=".jsp"/>
applicationContext.xml配置
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
<property name="configurationClass"
value="org.hibernate.cfg.AnnotationConfiguration">
</property>
</bean>
<!-- 配置事务管理器 -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<!-- 为事务管理器依赖注入sessionFactory实例 -->
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 配置事务拦截器 -->
<bean id="transactionInteceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<!-- 事务拦截器bean需要依赖注入一个事务管理器 -->
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<!-- 下面定义事务传播属性 -->
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<!-- 定义BeanNameAutoProxyCreator -->
<bean
class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<!-- 指定满足那些bean name的bean自动生成业务代理 -->
<property name="beanNames">
<!-- 下面是所有需要自动创建事务代理的bean -->
<list>
<value>*Dao</value>
<value>*Service</value>
</list>
</property>
<!-- 下面定义BeanNameAutoProxyCreator所需的事务拦截器 -->
<property name="interceptorNames">
<list>
<value>transactionInteceptor</value>
</list>
</property>
</bean>
<!-- 配置 Dao组件 -->
<bean id="UserDao" class="pro.login.dao.UserDaoImpl">
<!-- 依赖注入sessionFactory引用 -->
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<!-- 配置业务逻辑组件 -->
<bean id="UserService"
class="pro.login.service.UserServiceImpl">
<!-- 依赖注入业务逻辑组件所必需的DAO组件 -->
<property name="UserDao" ref="UserDao" />
</bean>
<!-- 配置业务逻辑组件 -->
<bean id="loginController"
class="pro.login.controller.loginController">
<!-- 依赖注入业务逻辑组件所必需的DAO组件 -->
<property name="UserService" ref="UserService" />
</bean>
2011年12月14日 16:37
1个答案 按时间排序 按投票排序
-
如果你采用了annotation的方式来注入,就没有必要在xml里面配置一次了
你直接删掉annotation试试。看配置文件没什么问题
除非你 pro.login.service.UserServiceImpl userService
解决办法:
1.删掉annotation
2.把 loginController里面的UserService属性改为小写的userService
3.给loginController的userService 一个setter方法
4. <property name="UserService" ref="UserService" />
改成 <property name="userService" ref="UserService" />
2011年12月14日 23:22
相关推荐
本实践指南将深入探讨Spring配置的最佳实践,旨在帮助开发者优化代码,提高应用的可维护性和可扩展性。 一、XML配置与Java配置的选择 Spring最初是以XML配置为主,但随着版本的更新,Java配置逐渐成为首选。Java...
【jbpm+spring配置】是将业务流程管理(Business Process Management, BPM)框架jbpm与企业级应用开发框架Spring相结合的实践。jbpm是一个开源的BPM解决方案,它提供了流程定义、执行、监控和管理的一整套工具。而...
为了使自定义的异常处理生效,还需要在Spring Boot配置文件中进行相应的配置。通常情况下,可以通过在`application.yml`或`application.properties`中添加以下内容来启用自定义异常处理: ```yaml spring: main: ...
Spring框架在企业级Java应用中广泛用于实现...总的来说,Spring配置JTA事务管理是一项关键任务,它确保了在分布式环境下的数据一致性。理解并正确配置JTA事务管理,能够让你的应用程序更加健壮,适应复杂的企业级需求。
【MyBatis-Spring配置教程】是一份专为初学者设计的教程,旨在帮助学习者快速掌握如何在Spring框架中整合并使用MyBatis。MyBatis是一个优秀的持久层框架,它支持定制化SQL、存储过程以及高级映射,而Spring则是一个...
接下来,一旦检测到Spring配置文件发生变化,我们需要重新加载配置文件。这可以通过Spring的`ApplicationContext`的`refresh()`方法来实现。`refresh()`会重新初始化Bean工厂,读取新的配置信息,并更新所有Bean的...
本文将深入探讨Spring MVC中的异常处理机制,帮助你更好地理解如何优雅地处理错误和异常。 1. **Spring MVC 异常处理概述** Spring MVC 提供了一种统一的方式来处理应用程序中抛出的异常。它通过`@...
当一个服务器不可用时,Spring配置的连接工厂会自动尝试连接到Zookeeper中标识的其他复制节点。 以上就是关于“activemq spring 客户端配置”的主要内容。通过这些步骤,你可以构建一个能够在Spring环境中与...
在这个"spring + redis + sentinel"配置中,我们将探讨如何整合这三个组件以创建一个稳定且高度可用的缓存系统。 首先,`redis.properties`文件是Spring与Redis连接的关键配置文件。在该文件中,通常会包含以下内容...
在本文中,我们将深入探讨Spring Security的配置及其在实际应用中的使用。 首先,Spring Security的核心概念包括用户、角色、权限和访问控制。它提供了一种机制来验证用户身份(身份验证),并决定用户是否可以访问...
本文将深入探讨Spring MVC中的异常处理机制,包括如何配置、自定义异常处理器以及异常转换策略。 首先,Spring MVC允许我们利用`@ExceptionHandler`注解来指定特定的控制器方法来处理特定类型的异常。例如,如果一...
总结来说,这篇博文探讨了如何在Spring中使用线程池执行定时任务,包括配置线程池、创建定时任务、异常处理和线程安全。同时,提到了Spring MVC在Web开发中的角色,以及它如何与任务调度协同工作。理解和掌握这些...
6. **异常处理**:配置全局的异常处理,捕获未授权(AccessDeniedException)和认证失败(AuthenticationException)等异常。 7. **过滤器链**:Spring Security通过一系列过滤器处理HTTP请求,如`...
如果配置文件位置有误或路径指定不正确,Spring将无法找到所需的配置文件,从而导致应用启动失败或行为异常。 此外,配置文件的位置和名称对于Spring来说是敏感的。如果存在同名的配置文件,但位于不同的位置,根据...
- **自定义异常处理器**:创建一个实现`HandlerExceptionResolver`接口的类,然后在Spring配置中注册这个处理器。 - **@ExceptionHandler**:在Controller类或方法上使用`@ExceptionHandler`注解来指定处理特定异常...
综上所述,配置Spring MVC请求的默认处理器涉及到web.xml的DispatcherServlet配置、Spring MVC配置文件的编写以及处理器映射、适配、拦截器和异常处理等相关组件的设置。理解并熟练掌握这些知识点,对于开发高效、...
在这个压缩包中,我们很可能会找到与Spring 3.1配置相关的各种文件,如XML配置文件、Java配置类以及相关文档。 1. **Spring核心**:Spring的核心特性包括依赖注入(Dependency Injection,DI)和面向切面编程...
在深入探讨Spring通知的配置之前,我们先简要回顾一下Spring框架的核心概念。Spring是一个开源的、轻量级的Java应用框架,旨在简化企业级应用的开发。它提供了丰富的功能,包括依赖注入(Dependency Injection,DI)...
此外,为了处理事务,还需要在Spring配置文件中配置`PlatformTransactionManager`。对于Hibernate,我们使用`HibernateTransactionManager`: ```xml <bean id="transactionManager" class="org.springframework....
实际开发中,还需要考虑异常处理、熔断机制、负载均衡等高级特性,这些可以通过Spring Cloud Alibaba中的其他组件,如Sentinel、Seata等来实现。同时,为了提高项目的可维护性和扩展性,可以采用模块化设计,将不同...