I want to define a Spring Bean CLASS with NO Interface

前端 未结 3 1232
旧巷少年郎
旧巷少年郎 2021-01-02 13:34

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 w

相关标签:
3条回答
  • 2021-01-02 14:05

    you can write everything including the mapped controller in the xml as beans, then you don't need to write interfaces. otherwise, with using annotation you need to build interfaces to proxy them.

    0 讨论(0)
  • 2021-01-02 14:07

    If class to be proxied (by transactional proxy in your case) implements any interface (InitializingBean implemented by HibernateDaoSupport in 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 type MySampleService.

    If you don't want to use interface you can override the strategy used by transactional aspect by declaring <tx:annotation-driven> with proxy-target-class = "true".

    See also:

    • 7.6 Proxying mechanisms
    0 讨论(0)
  • 2021-01-02 14:17

    Check the following. Ensure you have CGLIB on your classpath.

    http://static.springsource.org/spring/docs/3.0.0.M3/spring-framework-reference/html/ch08s06.html

    0 讨论(0)
提交回复
热议问题