- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
由于此错误,我的 tomcat 拒绝启动我的应用程序
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)}
这是我的服务等级
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);
这是我的 Controller 类,它正在调用服务层
@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);
}
这是完整的 Controller 类
@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);
}
individual_service的完整服务接口(interface)类
包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);
}
请问哪里出了问题?
最佳答案
看起来应用程序上下文中没有加载Individual_Service 类的bean。造成这种情况的原因可能有多种。
<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>
或者在dispatcher-servlet.xml/applicationContext.xml中
<import resource="classpath:bean.xml" />
确保context:component-scan中的路径覆盖Individual_Service.java包
<context:component-scan base-package="net.service.datastore.*" />
希望其中一点能够解决您的问题。如果没有,请提供您的 web.xml 、dispatcher-servlet.xml 或 Spring 配置类和 individual_Service.java 。
关于java - 创建名称为 'Individual_Controller' : Injection of autowired dependencies failed; 的 bean 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38266141/
由于此错误,我的 tomcat 拒绝启动我的应用程序 Error creating bean with na me 'Individual_Controller': Injection of auto
我是一名优秀的程序员,十分优秀!