I want to define a Spring Bean CLASS with NO Interface

前端 未结 3 1350
旧巷少年郎
旧巷少年郎 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: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 with proxy-target-class = "true".

    See also:

    • 7.6 Proxying mechanisms

提交回复
热议问题