I have been trying to upgrade from JBOSS 5 to jboss 7 and I am getting the following exception.
at java.lang.Thread.run(Thread.java:619) [rt.jar:1.6.0_20]
Caused by: java.lang.IllegalArgumentException: JBAS011089: @Resource injection target is invalid. Only setter methods are allowed: void com.myaccount.admin.manager.dao.ManagerDaoImpl.init(com.ibatis.sqlmap.client.SqlMapClient)
at org.jboss.as.ee.component.deployers.ResourceInjectionAnnotationParsingProcessor.processMethodResource(ResourceInjectionAnnotationParsingProcessor.java:192)
at org.jboss.as.ee.component.deployers.ResourceInjectionAnnotationParsingProcessor.deploy(ResourceInjectionAnnotationParsingProcessor.java:153)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]
... 5 more
Here is the code
@Repository("managerDao")
public class ManagerDaoImpl extends SqlMapClientDaoSupport implements ManagerDao {
@Resource(name="sqlMapClient_ADMIN")
public void init(SqlMapClient sqlMapClient) {
setSqlMapClient(sqlMapClient);
}
......
I googled but except the source code of the jboss jar I didn't find anything.
If you'd look into ResourceInjectionAnnotationParsingProcessor
processMethodResource
source code you'd see:
if (!methodName.startsWith("set") || methodInfo.args().length != 1) {
throw new IllegalArgumentException("@Resource injection target is invalid. Only setter methods are allowed: " + methodInfo);
}
It checks if method name does not starts with "set"
it throws an exception. So either rename your init
method to start with set
or just inject the field, annotate your init
method with @PostConstruct annotation something like this:
@Autowired
private SqlMapClient sqlMapClient;
@PostConstruct
public void init() {
setSqlMapClient(sqlMapClient);
}
Annotating the method with post construct may be better solution as maybe in future you'll need to add (or change) something more for initialization, so the only thing you'll need to do is to modify init()
method.