[
https://issues.apache.org/jira/browse/WICKET-7170?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18040824#comment-18040824
]
ASF GitHub Bot commented on WICKET-7170:
----------------------------------------
hosea commented on PR #1310:
URL: https://github.com/apache/wicket/pull/1310#issuecomment-3581424582
Hi @martin-g ,
I do not agree. These classes were designed only for being used inside
AnnotProxyFieldValueFactoryTest.
A simple class, just to define a type without any properties and methods for
exactly on testclass like
static class Bean{
}
should always be a inner class of the testcalss.
And have a look at the classes SpringBeanInjectable and the (same-structure)
JakartaInjectInjectable:
public static class SpringBeanInjectable {
private Bean nobean;
@SpringBean
private Bean beanByClass;
@SpringBean(name = "somebean")
private Bean beanByName;
@SpringBean(required = false)
private Bean optional;
@Override
public String toString() {
return "SpringBeanInjectable";
}
}
It is exactly build for AnnotProxyFieldValueFactoryTest. From
AnnotProxyFieldValueFactoryTest:
obj.getClass().getDeclaredField("nobean");
obj.getClass().getDeclaredField("beanByClass");
obj.getClass().getDeclaredField("beanByName");
springBeanInjectable.getClass().getDeclaredField("optional");
So this classes should also be inner classes in my opinion.
The Marker-Interface Injectable and the testclasses
JakartaInjectAnnotProxyFieldValueFactoryTest and
SpringBeanAnnotProxyFieldValueFactoryTest could be removed, because I
integrated using @ParameterizedTest (test Jakarta-Inject and Spring-Bean-Inject
with same @ParameterizedTest)
Just not: The real diff in implementation ist not very much. This is just
adding one functionality and a small refactoring:
1. move the "isPrimary"-loop out in a a loop with a Predicate
2. move the "isFieldname"-Rule out in a method
3. Add implementation for "isDefaultCandidate"
But the test is massivley improved:
I replaced the 3 small and not very detailed methods "testFactory",
"testCache" and "testFailsIfBeanWithIdIsNotFound" with a bunch of methods
testing a lot a scenarios:
- shouldCreateProxyForBeanName
- shouldThrowExceptionIfBeanNameNotFound
- shouldCreateProxyForClass
- shouldThrowException_beanNameAmbiguous
- shouldCreateProxyForUniquePrimary_beanNameAmbiguous
- shouldCreateProxyForUniqueDefaultCandidate_beanNameAmbiguous
- shouldCreateProxyForFieldname_beanNameAmbiguous
- shouldIgnoreUnannotatedFields
- required
- optional
- testCacheForClass
- testCacheForBeanName
Kind regards
Hans
> SpringInjector / AnnotProxyFieldValueFactory does not consider
> defaultCandidate
> -------------------------------------------------------------------------------
>
> Key: WICKET-7170
> URL: https://issues.apache.org/jira/browse/WICKET-7170
> Project: Wicket
> Issue Type: Bug
> Components: wicket-spring
> Affects Versions: 10.7.0
> Reporter: Hans Schäfer
> Priority: Major
>
> Spring considers the defaultCandidate-Flag, supplementary to the
> autowireCandidate-Flag. This ist currently not supported by SpringInjector /
> AnnotProxyFieldValueFactory.
> Assume 2 Beans of the same Class / Type: one is autowiredCandidate=true /
> defaultCandidate=true, the second is autowireCandidate=true but
> defaultCandidate = false.
> Spring always chosses the first one for autowiring, if no explicit beanName
> is given.
> Wicket complains about 2 beans of same type.
> Spring had a similar issue when creating proxies for beans with
> defaultCandidate = false:
> [https://github.com/spring-projects/spring-framework/issues/35626]
> There is a Pull Request that fixes this issue:
> [https://github.com/apache/wicket/pull/1310]
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)