@Autowire strange problem

Posted by Javi on Stack Overflow See other posts from Stack Overflow or by Javi
Published on 2010-04-26T11:31:17Z Indexed on 2010/04/26 11:33 UTC
Read the original article Hit count: 400

Filed under:
|
|
|

Hello,

I have a strange behaviour when autowiring

I have a similar code like this one, and it works

@Controller
public class Class1 {
@Autowired
private Class2 object2;
    ...
}

@Service
@Transactional
public class Class2{
   ...
}

The problem is that I need that the Class2 implements an interface so I've only changed the Class2 so it's now like:

@Controller
public class Class1 {
@Autowired
private Class2 object2;
    ...
}

@Service
@Transactional
public class Class2 implements IServiceReference<Class3, Long>{
   ...
}

public interface IServiceReference<T, PK extends Serializable> {
    public T reference(PK id);
}

with this code I get a org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type for Class2. It seems that @ Transitional annotation is not compatible with the interface because if I remove the @Transitional annotation or the "implements IServiceReference" the problem disapears and the bean is injected (though I need to have both in this class). It also happens if I put the annotation @Transitional in the methods instead of in the Class.

I use Spring 3.0.2 if this helps.

Is not compatible the interface with the transactional method? May it be a Spring bug?

Thanks

© Stack Overflow or respective owner

Related posts about spring

Related posts about spring-mvc