spring – Injection of autowired dependencies failed;
spring – Injection of autowired dependencies failed;
The error shows that com.bd.service.ArticleService
is not a registered bean. Add the packages in which you have beans that will be autowired in your application context:
<context:component-scan base-package=com.bd.service/>
<context:component-scan base-package=com.bd.controleur/>
Alternatively, if you want to include all subpackages in com.bd
:
<context:component-scan base-package=com.bd>
<context:include-filter type=aspectj expression=com.bd.* />
</context:component-scan>
As a side note, if youre using Spring 3.1 or later, you can take advantage of the @ComponentScan
annotation, so that you dont have to use any xml configuration regarding component-scan. Use it in conjunction with @Configuration
.
@Controller
@RequestMapping(/Article/GererArticle)
@Configuration
@ComponentScan(com.bd.service) // No need to include component-scan in xml
public class ArticleControleur {
@Autowired
ArticleService articleService;
...
}
You might find this Spring in depth section on Autowiring useful.
Do you have a bean declared in your context file that has an id of articleService? I believe that autowiring matches the id of a bean in your context files with the variable name that you are attempting to Autowire.
spring – Injection of autowired dependencies failed;
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;
}
}
You change the private int pkgId line in change datatype int to primitive class name or add annotation @autowired