创建名为'Individual_Controller'的bean时出错:注入自动装配的依赖关系失败; [英] Error creating bean with name 'Individual_Controller': Injection of autowired dependencies failed;

查看:2884
本文介绍了创建名为'Individual_Controller'的bean时出错:注入自动装配的依赖关系失败;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 创建包含na 
的bean的错误

我的tomcat拒绝启动我的应用程序, Individual_Controller':注入自动装配依赖失败;
嵌套的异常是org.springframework.beans.factory.BeanCreationException:Cou
ld不自动填充字段:private net.service.datastore.Indiv
个人服务net.controller.Individual_Controller.S $ b $服务;嵌套的异常是org.springframework.beans.factory.NoSuchBeanDefiniti
onException:没有符合bean类型的

[net.service.datastore.Individual_Service]找到依赖关系:期望至少有1个bean qu
为此依赖关系的自动导向候选者。依赖注释:{@org
.springframework.beans.factory.annotation.Autowired(required = true)}
预计至少有一个bean符合
自动连线的条件。依赖注释:{@ org.springfr
amework.beans.factory.annotation.Autowired(required = true)}

这是我的服务课程

  public long createT(Individual individual); 
公共个人更新T(个人);
public void deleteT(String tin);
公共列表<个人> getAllTs();
public Individual getT(String t);
公共列表<个人> getAllTs(String individual);

这是我调用服务层的控制器类

  @Autowired 
私人Individual_Service服务;

@RequestMapping(searchT)
public ModelAndView searchT(@RequestParam(searchName)String searchName){
logger.info(Searching the T:+ searchName );
列表<个人> tList = service.getAllTs(searchName);
返回新的ModelAndView(serviceDescription,tList,tList);
}

这是完整的控制器类

  @Controller 
public class IndividualController {


private static final Logger logger = Logger.getLogger(IndividualController.class) ;

public IndividualController(){
System.out.println(Individual_Controller());
}

@Autowired
私人IndividualService服务;

@RequestMapping(searchT)
public ModelAndView searchT(@RequestParam(searchName)String searchName){
logger.info(Searching the T:+ searchName );
列表<个人> tinList = service.getAllTs(searchName);
返回新的ModelAndView(serviceDescription,tList,tList);
}

完成individual_service的服务接口类

package net.service.datastore;

  import java.util.List; 
导入net.model.Individual;

public interface IndividualService {

public long createT(Individual individual);
公共个人更新T(个人);
public void deleteT(String t);
公共列表<个人> getAllTs();
public Individual getT(String t);
公共列表<个人> getAllTs(String individual);
}

请问可能有什么错?

解决方案

看起来没有类Individual_Service的bean被加载到Application Context中。这可能有多种原因。


  1. 如果您使用基于xml的配置,请确保xml文件包含在web中。 xml使用ContextLoaderListner。

< listener>
< listener-class> org.springframework.web.context.ContextLoaderListener< / listener-class>
< / listener>
< context-param>
< param-name> contextConfigLocation< / param-name>
< param-value>
classpath:spring-bean.xml
< / param-value>



或在dispatcher-servlet.xml / applicationContext.xml中

 < import resource =classpath:bean.xml/> 




  1. 如果您使用基于注释的方法,确保该类已使用@Component或@Bean或@Service正确注释或基于应用程序要求进行了任何其他注释。

确保路径在上下文中:component-scan覆盖Individual_Service.java的包

 < context:component-scan base-package = net.service.datastore。*/> 

希望其中一点能够解决您的问题。
如果不能,请提供您的web.xml,dispatcher-servlet.xml或Spring配置类和Individual_Service.java。


My tomcat is refusing to launch my application due to this error

Error creating bean with na
me 'Individual_Controller': Injection of autowired dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException: Cou
ld not autowire field: private net.service.datastore.Indiv
idual_Service net.controller.Individual_Controller.S
ervice; nested exception is org.springframework.beans.factory.NoSuchBeanDefiniti
onException: No qualifying bean of type 

[net.service.datastore.Individual_Service] found for dependency: expected at least 1 bean which qu
    alifies as autowire candidate for this dependency. Dependency annotations: {@org
    .springframework.beans.factory.annotation.Autowired(required=true)}
expected at least 1 bean which qualifies a
s autowire candidate for this dependency. Dependency annotations: {@org.springfr
amework.beans.factory.annotation.Autowired(required=true)}

this is my service class

public long createT(Individual individual);
    public Individual updateT(Individual individual);
    public void deleteT(String tin);
    public List<Individual> getAllTs();
    public Individual getT(String t);   
    public List<Individual> getAllTs(String individual);

this is my controller class that is calling the service layer

@Autowired
    private Individual_Service service;

    @RequestMapping("searchT")
    public ModelAndView searchT(@RequestParam("searchName") String searchName) {  
        logger.info("Searching the T: "+searchName);
        List<Individual> tList = service.getAllTs(searchName);
        return new ModelAndView("serviceDescription", "tList", tList);      
    }

this is the complete controller class

@Controller
public class IndividualController {


private static final Logger logger = Logger.getLogger(IndividualController.class);

    public IndividualController() {
        System.out.println("Individual_Controller()");
    }

    @Autowired
    private IndividualService service;

    @RequestMapping("searchT")
    public ModelAndView searchT(@RequestParam("searchName") String searchName) {  
        logger.info("Searching the T: "+searchName);
        List<Individual> tinList = service.getAllTs(searchName);
        return new ModelAndView("serviceDescription", "tList", tList);      
    }

complete service interface class for the individual_service

package net.service.datastore;

import java.util.List;
import net.model.Individual;

public interface IndividualService {

    public long createT(Individual individual);
    public Individual updateT(Individual individual);
    public void deleteT(String t);
    public List<Individual> getAllTs();
    public Individual getT(String t);   
    public List<Individual> getAllTs(String individual);
    }

Please what could be wrong?

解决方案

Looks like no bean of class Individual_Service is loaded in Application Context. There can be multiple reasons for that.

  1. If you are using xml based configuration , please make sure that xml file is either included in web.xml using ContextLoaderListner.

<listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:spring-bean.xml </param-value> </context-param>

or in dispatcher-servlet.xml / applicationContext.xml

<import resource="classpath:bean.xml" />

  1. If you are using annotation based Approach , make sure the class is properly annotated with @Component or @Bean or @Service or any other annotation based on application requirement.

Make sure path in context:component-scan is covering the package of Individual_Service.java

<context:component-scan base-package="net.service.datastore.*" />

Hope one of these point resolve your issue. If not can you please provide your web.xml , dispatcher-servlet.xml or Spring configuration class and Individual_Service.java .

这篇关于创建名为'Individual_Controller'的bean时出错:注入自动装配的依赖关系失败;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆