[
https://issues.apache.org/jira/browse/WICKET-1130?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12634880#action_12634880
]
Tuomas Karkkainen commented on WICKET-1130:
-------------------------------------------
injecting concrete classes without zero argument constructor into wicket
components fails, even if the injection is properly configured.
I have this:
public ConcreteClass(String a, String b) { ... }
bind(ConcreteClass.class).toInstance(new ConcreteClass("a","b"));
if I have
@Inject
private ConcreteClass concreteClass
in a wicket component it will not be injected but cglib will complain. If I
have it instead in a secondary dependency guice will inject it fine, which is
confusing. e.g.
public class ConcreteClassHolder {
@Inject
private ConcreteClass concreteClass;
public getConcreteClass(){...}
}
public class SomethingPanel extends Panel{
@Inject
private ConcreteClassHolder concreteClassHolder;
}
Instead of confusingly failing, with a "Superclass has no null constructors but
no arguments were given", I would prefer wicket to atleast check for this
condition in LazyInitProxyFactory:
public static Object createProxy(final Class type, final IProxyTargetLocator
locator) {
...
return e.create();
}
with maybe:
try {
return e.create();
} catch (final IllegalArgumentException iae) {
throw new RuntimeException("Cannot proxy concrete class with no
zero args constructor here, use an interface or see JIRA issue WICKET-1130.");
}
> Injection of Bound Instance Fails with Exception
> ------------------------------------------------
>
> Key: WICKET-1130
> URL: https://issues.apache.org/jira/browse/WICKET-1130
> Project: Wicket
> Issue Type: Bug
> Components: wicket-guice
> Affects Versions: 1.3.0-beta4
> Reporter: Daniel Spiewak
> Assignee: Alastair Maw
> Fix For: 1.5-M1
>
>
> If I try to inject an explicitly bound instance into a component, injection
> fails with an exception in the creation of the CGLIB proxy:
> java.lang.IllegalArgumentException: Superclass has no null constructors but
> no arguments were given
> Stupidly, I forgot to save the whole stack trace and the code is now gone
> from my codebase (since I needed it to work). To repeat:
> @Override
> public void configure() {
> bind(EntityManager.class).toInstance(manager);
> }
> Seems wicket-guice is assuming that it needs to create a new instance of
> everything that's injected, and since EntityManager doesn't have a no-args
> constructor, such an action fails. Just an assumption anyway...
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.