Results 1 to 3 of 3

Thread: Issue with Proxy Generation for multiple interfaces

  1. #1
    Join Date
    Dec 2004
    Posts
    8

    Default Issue with Proxy Generation for multiple interfaces

    I run into an issue attempting to directly implement multiple unrelated interfaces in a JavaConfig managed bean:

    public class MyServiceImpl implements MyService, ApplicationListener {
    ...
    }

    @Bean(scope=DefaultScopes.SINGLETON)
    public MyService myService() {
    return new MyServiceImpl();
    }

    While above setup works fine to expose the business interface of my service, it does not make it available as event listener.

    When changing (in an attempt to make the event listener portion work) the return type:

    @Bean(scope=DefaultScopes.SINGLETON)
    public MyServiceImpl myService() {
    return new MyServiceImpl();
    }

    An error is raised that the generated proxy cannot be cast to the expected return type. That's because a JDK proxy is generated for the interfaces, but not the implementation class. That's OK, I do not want the implementation to be exposed in any case.

    As workaround, I extended MyService from ApplicationListener and things work as expected. The bean is now found in the bean factory as an event listener a receives events.

    It seems a bit odd having to mingle interfaces like this through, there must be a better way to do this.

    What's the recommended approach to implement multiple interfaces and have them all exposed within the app context?

  2. #2
    Join Date
    Apr 2007
    Posts
    307

    Default

    Hi, thanks for posting this. It's possible there is an issue/bug going on here, but I'll need a little more info. Please create a bug report at http://jira.springsource.org (under the Spring Framework project, not under Spring JavaConfig). Be sure to note whether you're seeing this behavior against Spring JavaConfig 1.0.0.M4 or the Spring 3.0 milestones (I don't know which you're using right now).

    If you can attach a working example (preferably built with Maven) that demonstrates the issues, that will be most helpful. Thanks!
    Chris Beams
    Spring Framework committer, VMware
    http://github.com/cbeams

  3. #3
    Join Date
    Dec 2004
    Posts
    8

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •