Wicket
  1. Wicket
  2. WICKET-5052

@SpringBean fails to invoke methods on bean with non-public methods

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 6.6.0, 1.5.10
    • Fix Version/s: 6.7.0, 1.5.11
    • Component/s: wicket-spring
    • Labels:
      None
    • Environment:
      Tomcat 6.0.35
      Java 1.6.0.37

      Description

      @SpringBean fails to inject properly classes with a composite interface.

      eg :

      interface Something1 {}

      interface Something2 {}

      edit-public-edit interface Something extends Something1, Something2 {}

      class TestBean implements Something {}

      public class TestPage extends WebPage

      { @SpringBrean private Something something; }

      Trying to inject a bean implementing the Something interface does not seems to fail at first, but when calling any method an IllegalAccessException is thrown, similar to this :
      java.lang.IllegalAccessException: Class org.apache.wicket.proxy.LazyInitProxyFactory$JdkHandler can not access a member of class

      {replaced}

      with modifiers "public abstract"

      I've attached different test cases reproducing the problem.

      As a side note, referencing directly the implementing class like this seems to work :

      public class TestPage extends WebPage

      { @SpringBrean private TestBean something; }

      But it kind of defeats the purpose of DI.

      edit The visibility of the main interface was incorrectly listed as package-private, it is public (otherwise you can't reference it).

      1. springbean-tests.tgz
        21 kB
        Antoine Dupuis

        Activity

        Hide
        Martin Grigorov added a comment - - edited

        The problem is related to the visibility of the interfaces. All of them have package visibility.
        Make com.mycompany.service1.TestService1Sub1 and com.mycompany.service1.TestService1Sub2 public and the test passes.
        No need to make the impls visible.

        Wicket creates serializable proxy around the Spring bean. So it needs to be able to see the methods in the interfaces. The test passes if you use just pure Spring code only because the test class is in the same package as the service interfaces and impls. But since the proxy is in org.apache.wicket.ioc package it cannot see the methods.

        Show
        Martin Grigorov added a comment - - edited The problem is related to the visibility of the interfaces. All of them have package visibility. Make com.mycompany.service1.TestService1Sub1 and com.mycompany.service1.TestService1Sub2 public and the test passes. No need to make the impls visible. Wicket creates serializable proxy around the Spring bean. So it needs to be able to see the methods in the interfaces. The test passes if you use just pure Spring code only because the test class is in the same package as the service interfaces and impls. But since the proxy is in org.apache.wicket.ioc package it cannot see the methods.
        Hide
        Martin Grigorov added a comment -

        Fixed by making the method of the proxied bean accessible (method.setAccessible(true)).

        Show
        Martin Grigorov added a comment - Fixed by making the method of the proxied bean accessible (method.setAccessible(true)).
        Hide
        Antoine Dupuis added a comment -

        I edited the issue description, as I had incorrectly listed the Something interface as package-private.

        Otherwise, I think I understand why it isn't working at the moment, but I don't think I should have to expose the underlying interfaces by making them public for the injection to work.

        Thanks for the fix.

        Show
        Antoine Dupuis added a comment - I edited the issue description, as I had incorrectly listed the Something interface as package-private. Otherwise, I think I understand why it isn't working at the moment, but I don't think I should have to expose the underlying interfaces by making them public for the injection to work. Thanks for the fix.

          People

          • Assignee:
            Martin Grigorov
            Reporter:
            Antoine Dupuis
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development