I have a spring bean that extends HibernateDaoSupport. I want this bean injected into my Controllers, but I do NOT want it to implement any interface. I just want to refer to the concrete class from within the rest of my code (not use the AopProxy perhaps?) Does anyone have a way of doing this?
<bean id="mySampleService" class="com.sample.MySampleService">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
@Autowired
private MySampleService mySampleService;
... getters and setters ....
I know it’s a good idea to use the interface and that’s the whole point of IoC, but PLEASE DON’T suggest I use the interface.
If class to be proxied (by transactional proxy in your case) implements any interface (
InitializingBeanimplemented byHibernateDaoSupportin your case), Spring by default uses proxying strategy based on JDK dynamic proxies.So, it creates a proxy of type
InitializingBean, that, obviously, cannot be injected into a field of typeMySampleService.If you don’t want to use interface you can override the strategy used by transactional aspect by declaring
<tx:annotation-driven>withproxy-target-class = "true".See also: