[SPRING] autowired 종속성의 주입이 실패했습니다.
SPRINGautowired 종속성의 주입이 실패했습니다.
작은 Java EE Hibernate Spring 애플리케이션을 개발 중이며 오류가 발생했습니다. 'articleControleur'라는 이름의 빈을 생성하는 중 오류가 발생했습니다. 자동 생성 된 종속성의 삽입이 실패했습니다.
oct. 26, 2011 3:51:44 PM org.apache.catalina.core.ApplicationContext log
Grave: StandardWrapper.Throwable
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'articleControleur': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.bd.service.ArticleService com.bd.controleur.ArticleControleur.articleService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.bd.service.ArticleService] 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)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:285)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4350)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4659)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
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: com.bd.service.ArticleService com.bd.controleur.ArticleControleur.articleService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.bd.service.ArticleService] 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)}
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:502)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:282)
... 33 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.bd.service.ArticleService] 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)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:920)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:789)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:474)
... 35 more
oct. 26, 2011 3:51:44 PM org.apache.catalina.core.StandardContext loadOnStartup
Grave: La servlet /ExempleAchref a généré une exception "load()"
org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.bd.service.ArticleService] 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)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:920)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:789)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:703)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:474)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:282)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1074)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:442)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:458)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:339)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:306)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4350)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4659)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
at org.apache.catalina.core.StandardService.start(StandardService.java:519)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
그리고 여기 기사 목록을 복구하는 기능이 포함 된 내 컨트롤러 ArticleControleur가 있습니다.
package com.bd.controleur;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.bd.service.ArticleService;
@Controller
@RequestMapping("/Article/GererArticle")
public class ArticleControleur {
@Autowired
ArticleService articleService;
public ModelAndView listarticle() {
Map<String, Object> model = new HashMap<String, Object>();
model.put("articles", articleService.getAllArticles());
// new ModelAndView("nom de la page jsp", model qui contient l'ensemble
// des beans que tu vas passer a cette page)
return new ModelAndView("GererArticle", model);
}
}
그리고 여기 내 기사 서비스입니다 :
package com.bd.service;
import java.util.Collection;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.bd.dao.ArticleDao;
import com.bd.entity.Article;
@Service
public class ArticleServiceImp implements ArticleService {
@Autowired
private ArticleDao articledao;
@Override
public Article getArticleById(int articleId) {
// TODO Auto-generated method stub
return articledao.getById(articleId);
}
@Override
public void saveArticle(Article article) {
// TODO Auto-generated method stub
articledao.save(article);
}
@Override
public void deleteArticle(Article article) {
// TODO Auto-generated method stub
articledao.delete(article);
}
@Override
public List<Article> getAllArticles() {
// TODO Auto-generated method stub
return articledao.getAll();
}
}
그리고 여기 내 응용 프로그램 컨텍스트가 있습니다 :
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Application context containing authentication, channel
- security and web URI beans.
-
- Only used by "filter" artifact.
-
-->
<b:beans xmlns:b="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-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
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
">
<!-- Auto-detect components -->
<context:component-scan base-package="com.bd.entity"/>
</b:beans>
해결법
-
==============================
1.이 오류는 com.bd.service.ArticleService가 등록 된 bean이 아님을 보여줍니다. 응용 프로그램 컨텍스트에서 autowired 될 bean이있는 패키지를 추가하십시오.
이 오류는 com.bd.service.ArticleService가 등록 된 bean이 아님을 보여줍니다. 응용 프로그램 컨텍스트에서 autowired 될 bean이있는 패키지를 추가하십시오.
<context:component-scan base-package="com.bd.service"/> <context:component-scan base-package="com.bd.controleur"/>
또는 com.bd에 모든 하위 패키지를 포함하려는 경우
<context:component-scan base-package="com.bd"> <context:include-filter type="aspectj" expression="com.bd.*" /> </context:component-scan>
부가 적으로 Spring 3.1 또는 그 이후 버전을 사용한다면 @ComponentScan 어노테이션을 이용할 수 있기 때문에 컴포넌트 스캔과 관련하여 xml 설정을 사용할 필요가 없다. @Configuration과 함께 사용하십시오.
@Controller @RequestMapping("/Article/GererArticle") @Configuration @ComponentScan("com.bd.service") // No need to include component-scan in xml public class ArticleControleur { @Autowired ArticleService articleService; ... }
이 스프링은 Autowiring에서 유용 할 것입니다.
-
==============================
2.id가 "articleService"인 컨텍스트 파일에 선언 된 bean이 있습니까? 자동 와이어 링은 컨텍스트 파일의 bean id를 Autowire로 시도하는 변수 이름과 일치시킵니다.
id가 "articleService"인 컨텍스트 파일에 선언 된 bean이 있습니까? 자동 와이어 링은 컨텍스트 파일의 bean id를 Autowire로 시도하는 변수 이름과 일치시킵니다.
-
==============================
3.
public class Organization { @Id @Column(name="org_id") @GeneratedValue private int id; @Column(name="org_name") private String name; @Column(name="org_office_address1") private String address1; @Column(name="org_office_addres2") private String address2; @Column(name="city") private String city; @Column(name="state") private String state; @Column(name="country") private String country; @JsonIgnore @OneToOne @JoinColumn(name="pkg_id") private int pkgId; public int getPkgId() { return pkgId; } public void setPkgId(int pkgId) { this.pkgId = pkgId; } public String getCountry() { return country; } public void setCountry(String country) { this.country = country; } @Column(name="pincode") private String pincode; @OneToMany(mappedBy = "organization", cascade=CascadeType.ALL, fetch = FetchType.EAGER) private Set<OrganizationBranch> organizationBranch = new HashSet<OrganizationBranch>(0); @Column(name="status") private String status = "ACTIVE"; @Column(name="project_id") private int redmineProjectId; public int getRedmineProjectId() { return redmineProjectId; } public void setRedmineProjectId(int redmineProjectId) { this.redmineProjectId = redmineProjectId; } public String getStatus() { return status; } public void setStatus(String status) { this.status = status; } public Set<OrganizationBranch> getOrganizationBranch() { return organizationBranch; } public void setOrganizationBranch(Set<OrganizationBranch> organizationBranch) { this.organizationBranch = organizationBranch; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAddress1() { return address1; } public void setAddress1(String address1) { this.address1 = address1; } public String getAddress2() { return address2; } public void setAddress2(String address2) { this.address2 = address2; } public String getCity() { return city; } public void setCity(String city) { this.city = city; } public String getState() { return state; } public void setState(String state) { this.state = state; } public String getPincode() { return pincode; } public void setPincode(String pincode) { this.pincode = pincode; } }
변경 데이터 유형 int의 개인 int pkgId 행을 기본 클래스 이름으로 변경하거나 주석을 @autowired
from https://stackoverflow.com/questions/7914363/injection-of-autowired-dependencies-failed by cc-by-sa and MIT license
'SPRING' 카테고리의 다른 글
[SPRING] applicationContext가 서블릿 컨텍스트에 대한 컨트롤러를 찾지 못했습니다. (0) | 2018.12.23 |
---|---|
[SPRING] Spring MVC - REST 서비스의 빈리스트에 @Valid (0) | 2018.12.23 |
[SPRING] Spring REST Service : json 응답에서 null 객체를 제거하도록 구성하는 방법 (0) | 2018.12.23 |
[SPRING] 모든 컨트롤러와 매핑을보기에 표시하는 방법 (0) | 2018.12.23 |
[SPRING] jpa / hibernate가있는 Spring에서 초기화 지연 예외를 피하기 위해 세션을 어떻게 열어 두어야합니까? (0) | 2018.12.23 |