Reputation: 127
I have encountered below BeanDefinitionDecorator error at below constructor-arg dependency line in Bean XML (root-context.xml) in Eclipse, but no issue when using setter injection with property element, appreciate if anyone here could provide advice, as not able to identify the root cause even after search through Internet. Thanks in advance.
Error encountered
"Multiple annotations found at this line:
Cannot locate BeanDefinitionDecorator for element [constructor-arg]
cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'constructor-arg'.
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<beans:bean id="myObject" class="com.packapp.MyObject"></beans:bean>
<beans:bean id="homeDAO" class="com.packapp.HomeDAOImpl">
<constructor-arg><ref bean="myObject"/></constructor-arg>
</beans:bean>
<beans:bean id = "homeService" class="com.packapp.HomeServiceImpl">
<beans:property name="homeDAO" ref="homeDAO"></beans:property>
</beans:bean>
<context:component-scan base-package="com.packapp" />
</beans:beans>
public class MyObject {
private String homeName;
private String homeAddress;
public String getHomeName(){
return homeName;
}
public void setHomeName(String homeName){
this.homeName = homeName;
}
public String getHomeAddress(){
return homeAddress;
}
public void setHomeAddress(String homeAddress){
this.homeAddress = homeAddress;
}
}
@Repository
public class HomeDAOImpl implements HomeDAO {
private MyObject obj;
public HomeDAOImpl(MyObject obj){
this.obj = obj;
}
public String getAddress() {
return this.obj.getHomeAddress();
}
}
@Service
public class HomeServiceImpl implements HomeService {
private HomeDAO homeDAO;
public void setHomeDAO(HomeDAO homeDAO){
this.homeDAO = homeDAO;
}
public String getAddress() {
return this.homeDAO.getAddress();
}
@Controller
@RequestMapping("ctrl2")
public class HomeController2 {
private HomeService homeService;
@Autowired(required=true)
@Qualifier(value="homeService")
public void setHomeService (HomeService hs){
this.homeService = hs;
}
@RequestMapping(value = "/site2", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
Date date = new Date();
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
String formattedDate = dateFormat.format(date);
model.addAttribute("serverTime", formattedDate + this.homeService.getAddress());
return "home2";
}
}
Upvotes: 0
Views: 1413
Reputation: 69505
I think <constructor-arg><ref bean="myObject"/></constructor-arg>
must be <beans:constructor-arg><beans:ref bean="myObject"/></beans:constructor-arg>
because you have a prefix for elements in spring-beans.xsd
.
Upvotes: 3