tomcat启动Error creating bean with name 'loginController'

J2EE 码拜 10年前 (2015-04-07) 1060次浏览 0个评论

2014-10-29 09:08:57,385 ERROR [main] (FrameworkServlet.java:470) – Context initialization failed
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 com.baobaotao.service.UserService com.baobaotao.web.LoginController.userService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.baobaotao.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.Qualifier(value=userService)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1146)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:628)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:651)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:602)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:665)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:521)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:462)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1206)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1026)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4421)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4734)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.baobaotao.service.UserService com.baobaotao.web.LoginController.userService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.baobaotao.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.Qualifier(value=userService)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:517)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:286)
… 43 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.baobaotao.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.Qualifier(value=userService)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:988)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:858)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:770)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:489)
… 45 more

求大神查看啊 , 谢谢啦  

tomcat启动Error creating bean with name 'loginController'
各路大神 帮小弟看看  
tomcat启动Error creating bean with name 'loginController'
10分
自动注入userService的时候错了。你看看那里用了,贴出代码大家看看
tomcat启动Error creating bean with name 'loginController'
引用 2 楼 w3226327 的回复:

自动注入userService的时候错了。你看看那里用了,贴出代码大家看看

package com.baobaotao.web;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.baobaotao.domain.User;
import com.baobaotao.service.UserService;

@Controller(“loginController”)
public class LoginController{

@Autowired
@Qualifier(“userService”)
private UserService userService;
    
@RequestMapping(value = “/index.html”)
public String loginPage(){
return “login”;
}

@RequestMapping(value = “/loginCheck.html”)
public ModelAndView loginCheck(HttpServletRequest request,LoginCommand loginCommand){
boolean isValidUser = 
   userService.hasMatchUser(loginCommand.getUserName(),
                    loginCommand.getPassword());
if (!isValidUser) {
return new ModelAndView(“login”, “error”, “用户名或密码错误。”);
} else {
User user = userService.findUserByUserName(loginCommand
.getUserName());
user.setLastIp(request.getLocalAddr());
user.setLastVisit(new Date());
userService.loginSuccess(user);
request.getSession().setAttribute(“user”, user);
return new ModelAndView(“main”);
}
}

public UserService getUserService() {
return userService;
}

public void setUserService(UserService userService) {
this.userService = userService;
}
}

这是LoginController的全部代码

tomcat启动Error creating bean with name 'loginController'
配置文件的代码如下

<?xml version=”1.0″ encoding=”UTF-8″ ?>
<beans xmlns=”http://www.springframework.org/schema/beans”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xmlns:p=”http://www.springframework.org/schema/p”
xmlns:context=”http://www.springframework.org/schema/context”
xmlns:aop=”http://www.springframework.org/schema/aop” xmlns:tx=”http://www.springframework.org/schema/tx”
xsi:schemaLocation=”http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
       http://www.springframework.org/schema/context 
       http://www.springframework.org/schema/context/spring-context-3.0.xsd
       http://www.springframework.org/schema/tx 
       http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
       http://www.springframework.org/schema/aop
       http://www.springframework.org/schema/aop/spring-aop-3.0.xsd”>
    
    <!– 扫描类包,将标注Spring注解的类自动转化Bean,同时完成Bean的注入 –>
    <context:component-scan base-package=”com.baobaotao.dao”/>
    <context:component-scan base-package=”com.baobaotao.service”/>
    <context:component-scan base-package=”com.baobaotao.web”/>
    
    <!– 配置数据源 –>
<bean id=”dataSource” class=”org.apache.commons.dbcp.BasicDataSource”
destroy-method=”close” 
p:driverClassName=”com.mysql.jdbc.Driver”
p:url=”jdbc:mysql://localhost:3306/sampledb” 
p:username=”root”
p:password=”1234″ />

<!– 配置Jdbc模板  –>
<bean id=”jdbcTemplate” class=”org.springframework.jdbc.core.JdbcTemplate”
p:dataSource-ref=”dataSource” />

<!– 配置事务管理器 –>
<bean id=”transactionManager”
class=”org.springframework.jdbc.datasource.DataSourceTransactionManager”
p:dataSource-ref=”dataSource” />

<!– 通过AOP配置提供事务增强,让service包下所有Bean的所有方法拥有事务 –>
<aop:config proxy-target-class=”true”>
<aop:pointcut id=”serviceMethod”
expression=” execution(* com.baobaotao.service..*(..))” />
<aop:advisor pointcut-ref=”serviceMethod” advice-ref=”txAdvice” />
</aop:config>
<tx:advice id=”txAdvice” transaction-manager=”transactionManager”>
<tx:attributes>
<tx:method name=”*” />
</tx:attributes>
</tx:advice>
</beans>

tomcat启动Error creating bean with name 'loginController'
10分
看看是不是UserService 没有声明注册成springbean
tomcat启动Error creating bean with name 'loginController'
引用 5 楼 nyxiaobin123 的回复:

看看是不是UserService 没有声明注册成springbean

我在上面加了 @Service(“userService”)  

tomcat启动Error creating bean with name 'loginController'
20分
还想到2中可能性啊,经供参考,一个是你们UserService是接口类,注解放到实现类,还有就是是不是你的类没部署到tomcat里面啊?
tomcat启动Error creating bean with name 'loginController'
引用 7 楼 nyxiaobin123 的回复:

还想到2中可能性啊,经供参考,一个是你们UserService是接口类,注解放到实现类,还有就是是不是你的类没部署到tomcat里面啊?

第一种可能性,之前研究过 , 有做单元测试的 没问题 .  第二种可能性应该不会吧 ,我是用myeclipse发布到tomcat下的 , 发布到weblogic下也是报同样的错. 

tomcat启动Error creating bean with name 'loginController'
问题终于解决了  !!!~~    

是web.xml中的  
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>  

<param-value>classpath:applicationContext.xml</param-value>  这个写错了 我晕哦     


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明tomcat启动Error creating bean with name 'loginController'
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!