Author: mgrigorov
Date: Tue Dec 20 11:11:11 2011
New Revision: 1221201
URL: http://svn.apache.org/viewvc?rev=1221201&view=rev
Log:
WICKET-4307
Support javax.inject.Inject annotation in Guice and Spring integration
Added:
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/JavaxInjectGuiceInjectorTest.java
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/JavaxInjectTestBehavior.java
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/JavaxInjectTestComponent.java
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/JavaxInjectTestNoComponent.java
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/TestComponentInterface.java
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/TestNoComponentInterface.java
wicket/trunk/wicket-spring/src/test/java/org/apache/wicket/spring/injection/annot/JavaxInjectAnnotProxyFieldValueFactoryTest.java
wicket/trunk/wicket-spring/src/test/java/org/apache/wicket/spring/injection/util/InjectableInterface.java
wicket/trunk/wicket-spring/src/test/java/org/apache/wicket/spring/injection/util/JavaxInjectable.java
Modified:
wicket/trunk/wicket-guice/src/main/java/org/apache/wicket/guice/GuiceFieldValueFactory.java
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/GuiceInjectorTest.java
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/TestComponent.java
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/TestNoComponent.java
wicket/trunk/wicket-spring/src/main/java/org/apache/wicket/spring/injection/annot/AnnotProxyFieldValueFactory.java
wicket/trunk/wicket-spring/src/test/java/org/apache/wicket/spring/injection/annot/AnnotProxyFieldValueFactoryTest.java
wicket/trunk/wicket-spring/src/test/java/org/apache/wicket/spring/injection/util/Injectable.java
Modified:
wicket/trunk/wicket-guice/src/main/java/org/apache/wicket/guice/GuiceFieldValueFactory.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-guice/src/main/java/org/apache/wicket/guice/GuiceFieldValueFactory.java?rev=1221201&r1=1221200&r2=1221201&view=diff
==============================================================================
---
wicket/trunk/wicket-guice/src/main/java/org/apache/wicket/guice/GuiceFieldValueFactory.java
(original)
+++
wicket/trunk/wicket-guice/src/main/java/org/apache/wicket/guice/GuiceFieldValueFactory.java
Tue Dec 20 11:11:11 2011
@@ -55,13 +55,14 @@ public class GuiceFieldValueFactory impl
if (supportsField(field))
{
Inject injectAnnotation =
field.getAnnotation(Inject.class);
- if (!Modifier.isStatic(field.getModifiers()) &&
(injectAnnotation != null))
+ javax.inject.Inject javaxInjectAnnotation =
field.getAnnotation(javax.inject.Inject.class);
+ if (!Modifier.isStatic(field.getModifiers()) &&
(injectAnnotation != null || javaxInjectAnnotation != null))
{
try
{
Annotation bindingAnnotation =
findBindingAnnotation(field.getAnnotations());
final IProxyTargetLocator locator = new
GuiceProxyTargetLocator(field,
- bindingAnnotation,
injectAnnotation.optional());
+ bindingAnnotation,
injectAnnotation != null ? injectAnnotation.optional() : false);
if (wrapInProxies)
{
@@ -101,7 +102,7 @@ public class GuiceFieldValueFactory impl
*/
public boolean supportsField(final Field field)
{
- return field.isAnnotationPresent(Inject.class);
+ return field.isAnnotationPresent(Inject.class) ||
field.isAnnotationPresent(javax.inject.Inject.class);
}
/**
Modified:
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/GuiceInjectorTest.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/GuiceInjectorTest.java?rev=1221201&r1=1221200&r2=1221201&view=diff
==============================================================================
---
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/GuiceInjectorTest.java
(original)
+++
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/GuiceInjectorTest.java
Tue Dec 20 11:11:11 2011
@@ -90,15 +90,15 @@ public class GuiceInjectorTest extends A
// Create a new component, which should be
automatically injected,
// and test to make sure the injection has worked.
- TestComponent testComponent = new TestComponent("id");
+ TestComponentInterface testComponent =
newTestComponent("id");
doChecksForComponent(testComponent);
// Serialize and deserialize the object, and check it
still works.
- TestComponent clonedComponent =
(TestComponent)WicketObjects.cloneObject(testComponent);
+ TestComponentInterface clonedComponent =
(TestComponentInterface)WicketObjects.cloneObject(testComponent);
doChecksForComponent(clonedComponent);
// Test injection of a class that does not extend
Component
- TestNoComponent noncomponent = new TestNoComponent();
+ TestNoComponentInterface noncomponent =
newTestNoComponent();
doChecksForNoComponent(noncomponent);
}
@@ -109,12 +109,12 @@ public class GuiceInjectorTest extends A
}
}
- private void doChecksForNoComponent(final TestNoComponent component)
+ private void doChecksForNoComponent(final TestNoComponentInterface
noncomponent)
{
- assertEquals(ITestService.RESULT_RED, component.getString());
+ assertEquals(ITestService.RESULT_RED, noncomponent.getString());
}
- private void doChecksForComponent(final TestComponent component)
+ private void doChecksForComponent(final TestComponentInterface
component)
{
assertEquals(ITestService.RESULT,
component.getInjectedField().getString());
assertEquals(null, component.getInjectedOptionalField());
@@ -126,4 +126,14 @@ public class GuiceInjectorTest extends A
assertEquals(ITestService.RESULT,
component.getInjectedTypeLiteralField().get(ITestService.RESULT));
}
+
+ protected TestNoComponentInterface newTestNoComponent()
+ {
+ return new TestNoComponent();
+ }
+
+ protected TestComponentInterface newTestComponent(String id)
+ {
+ return new TestComponent(id);
+ }
}
Added:
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/JavaxInjectGuiceInjectorTest.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/JavaxInjectGuiceInjectorTest.java?rev=1221201&view=auto
==============================================================================
---
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/JavaxInjectGuiceInjectorTest.java
(added)
+++
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/JavaxInjectGuiceInjectorTest.java
Tue Dec 20 11:11:11 2011
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.guice;
+
+
+/**
+ */
+public class JavaxInjectGuiceInjectorTest extends GuiceInjectorTest
+{
+ @Override
+ protected TestComponentInterface newTestComponent(String id)
+ {
+ return new JavaxInjectTestComponent(id);
+ }
+
+ @Override
+ protected TestNoComponentInterface newTestNoComponent()
+ {
+ return new JavaxInjectTestNoComponent();
+ }
+}
Added:
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/JavaxInjectTestBehavior.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/JavaxInjectTestBehavior.java?rev=1221201&view=auto
==============================================================================
---
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/JavaxInjectTestBehavior.java
(added)
+++
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/JavaxInjectTestBehavior.java
Tue Dec 20 11:11:11 2011
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.guice;
+
+import javax.inject.Inject;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.behavior.Behavior;
+import org.junit.Assert;
+
+/**
+ * A behavior that will be use injected services
+ *
+ * https://issues.apache.org/jira/browse/WICKET-4149
+ */
+public class JavaxInjectTestBehavior extends Behavior
+{
+ private static final long serialVersionUID = 1L;
+
+ @Inject
+ @Blue
+ private ITestService injectedFieldBlue;
+
+ @Override
+ public void bind(Component component)
+ {
+ super.bind(component);
+
+ Assert.assertNotNull(injectedFieldBlue);
+ Assert.assertEquals("blue", injectedFieldBlue.getString());
+ }
+
+}
Added:
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/JavaxInjectTestComponent.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/JavaxInjectTestComponent.java?rev=1221201&view=auto
==============================================================================
---
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/JavaxInjectTestComponent.java
(added)
+++
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/JavaxInjectTestComponent.java
Tue Dec 20 11:11:11 2011
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.guice;
+
+import java.util.Map;
+
+import javax.inject.Inject;
+
+import org.apache.wicket.Component;
+
+import com.google.inject.Provider;
+
+/**
+ */
+public class JavaxInjectTestComponent extends Component implements
TestComponentInterface
+{
+ private static final long serialVersionUID = 1L;
+
+ @Inject
+ private ITestService injectedField;
+
+ @Inject
+ @Red
+ private ITestService injectedFieldRed;
+
+ @Inject
+ @Blue
+ private ITestService injectedFieldBlue;
+
+ @Inject
+ private Provider<ITestService> injectedFieldProvider;
+
+ @Inject
+ private Map<String, String> injectedTypeLiteralField;
+
+ private final JavaxInjectTestNoComponent noComponent;
+
+ /**
+ * Construct.
+ *
+ * @param id
+ */
+ public JavaxInjectTestComponent(final String id)
+ {
+ super(id);
+ noComponent = new JavaxInjectTestNoComponent();
+ add(new JavaxInjectTestBehavior());
+ }
+
+ /**
+ * @return injectedField
+ */
+ public ITestService getInjectedField()
+ {
+ return injectedField;
+ }
+
+ /**
+ * @return injectedFieldBlue
+ */
+ public ITestService getInjectedFieldBlue()
+ {
+ return injectedFieldBlue;
+ }
+
+ /**
+ * @return injectedFieldRed
+ */
+ public ITestService getInjectedFieldRed()
+ {
+ return injectedFieldRed;
+ }
+
+ /**
+ * @return injectedFieldProvider
+ */
+ public Provider<ITestService> getInjectedFieldProvider()
+ {
+ return injectedFieldProvider;
+ }
+
+ /**
+ * Gets injectedOptionalField.
+ *
+ * @return injectedOptionalField
+ */
+ public String getInjectedOptionalField()
+ {
+ return null;
+ }
+
+ /**
+ * @return injectedTypeLiteralField
+ */
+ public Map<String, String> getInjectedTypeLiteralField()
+ {
+ return injectedTypeLiteralField;
+ }
+
+ @Override
+ protected void onRender()
+ {
+ // Do nothing.
+ }
+
+ /**
+ * @return String for noComponent
+ */
+ public String getNoComponentString()
+ {
+ return noComponent.getString();
+ }
+
+}
Added:
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/JavaxInjectTestNoComponent.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/JavaxInjectTestNoComponent.java?rev=1221201&view=auto
==============================================================================
---
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/JavaxInjectTestNoComponent.java
(added)
+++
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/JavaxInjectTestNoComponent.java
Tue Dec 20 11:11:11 2011
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.guice;
+
+import javax.inject.Inject;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.IClusterable;
+import org.apache.wicket.injection.Injector;
+
+/**
+ * Tests injection of services in classes which do not extend {@link Component}
+ */
+@SuppressWarnings("serial")
+public class JavaxInjectTestNoComponent implements IClusterable,
TestNoComponentInterface
+{
+
+ @Inject
+ @Red
+ private ITestService testService;
+
+ /**
+ *
+ * Construct.
+ */
+ public JavaxInjectTestNoComponent()
+ {
+ Injector.get().inject(this);
+ }
+
+ /**
+ * @return if injection works should return {@link
ITestService#RESULT_RED}
+ */
+ public String getString()
+ {
+ return testService.getString();
+ }
+}
Modified:
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/TestComponent.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/TestComponent.java?rev=1221201&r1=1221200&r2=1221201&view=diff
==============================================================================
---
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/TestComponent.java
(original)
+++
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/TestComponent.java
Tue Dec 20 11:11:11 2011
@@ -26,7 +26,7 @@ import com.google.inject.name.Named;
/**
*/
-public class TestComponent extends Component
+public class TestComponent extends Component implements TestComponentInterface
{
private static final long serialVersionUID = 1L;
Added:
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/TestComponentInterface.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/TestComponentInterface.java?rev=1221201&view=auto
==============================================================================
---
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/TestComponentInterface.java
(added)
+++
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/TestComponentInterface.java
Tue Dec 20 11:11:11 2011
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.guice;
+
+import java.util.Map;
+
+import com.google.inject.Provider;
+
+public interface TestComponentInterface
+{
+
+ ITestService getInjectedField();
+
+ String getInjectedOptionalField();
+
+ ITestService getInjectedFieldRed();
+
+ ITestService getInjectedFieldBlue();
+
+ Provider<ITestService> getInjectedFieldProvider();
+
+ Map<String, String> getInjectedTypeLiteralField();
+
+}
Modified:
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/TestNoComponent.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/TestNoComponent.java?rev=1221201&r1=1221200&r2=1221201&view=diff
==============================================================================
---
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/TestNoComponent.java
(original)
+++
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/TestNoComponent.java
Tue Dec 20 11:11:11 2011
@@ -26,7 +26,7 @@ import com.google.inject.Inject;
* Tests injection of services in classes which do not extend {@link Component}
*/
@SuppressWarnings("serial")
-public class TestNoComponent implements IClusterable
+public class TestNoComponent implements IClusterable, TestNoComponentInterface
{
@Inject
Added:
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/TestNoComponentInterface.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/TestNoComponentInterface.java?rev=1221201&view=auto
==============================================================================
---
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/TestNoComponentInterface.java
(added)
+++
wicket/trunk/wicket-guice/src/test/java/org/apache/wicket/guice/TestNoComponentInterface.java
Tue Dec 20 11:11:11 2011
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.guice;
+
+public interface TestNoComponentInterface
+{
+
+ Object getString();
+
+}
Modified:
wicket/trunk/wicket-spring/src/main/java/org/apache/wicket/spring/injection/annot/AnnotProxyFieldValueFactory.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-spring/src/main/java/org/apache/wicket/spring/injection/annot/AnnotProxyFieldValueFactory.java?rev=1221201&r1=1221200&r2=1221201&view=diff
==============================================================================
---
wicket/trunk/wicket-spring/src/main/java/org/apache/wicket/spring/injection/annot/AnnotProxyFieldValueFactory.java
(original)
+++
wicket/trunk/wicket-spring/src/main/java/org/apache/wicket/spring/injection/annot/AnnotProxyFieldValueFactory.java
Tue Dec 20 11:11:11 2011
@@ -23,6 +23,9 @@ import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ConcurrentMap;
+import javax.inject.Inject;
+import javax.inject.Named;
+
import org.apache.wicket.injection.IFieldValueFactory;
import org.apache.wicket.proxy.LazyInitProxyFactory;
import org.apache.wicket.spring.ISpringContextLocator;
@@ -154,14 +157,24 @@ public class AnnotProxyFieldValueFactory
private String getBeanName(final Field field)
{
SpringBean annot = field.getAnnotation(SpringBean.class);
+
+ String name;
+ boolean required;
+ if (annot != null) {
+ name = annot.name();
+ required = annot.required();
+ } else {
+ Named named = field.getAnnotation(Named.class);
+ name = named != null ? named.value() : "";
+ required = false;
+ }
- String name = annot.name();
if (Strings.isEmpty(name))
{
name = beanNameCache.get(field.getType());
if (name == null)
{
- name =
getBeanNameOfClass(contextLocator.getSpringContext(), field.getType(), annot);
+ name =
getBeanNameOfClass(contextLocator.getSpringContext(), field.getType(),
required);
if (name != null)
{
@@ -180,13 +193,13 @@ public class AnnotProxyFieldValueFactory
* spring application context
* @param clazz
* bean class
- * @param annot
- * the SpringBean annotation
+ * @param required
+ * true if the value is required
* @throws IllegalStateException
* @return spring name of the bean
*/
private final String getBeanNameOfClass(final ApplicationContext ctx,
final Class<?> clazz,
- final SpringBean annot)
+ final boolean required)
{
// get the list of all possible matching beans
List<String> names = new ArrayList<String>(
@@ -212,7 +225,7 @@ public class AnnotProxyFieldValueFactory
if (names.isEmpty())
{
- if (annot.required())
+ if (required)
{
throw new IllegalStateException("bean of type
[" + clazz.getName() + "] not found");
}
@@ -244,7 +257,7 @@ public class AnnotProxyFieldValueFactory
msg.append("More than one bean of type [");
msg.append(clazz.getName());
msg.append("] found, you have to specify the name of
the bean ");
- msg.append("(@SpringBean(name=\"foo\")) in order to
resolve this conflict. ");
+ msg.append("(@SpringBean(name=\"foo\")) or
(@Named(\"foo\") if using @javax.inject classes) in order to resolve this
conflict. ");
msg.append("Matched beans: ");
msg.append(Strings.join(",", names.toArray(new
String[names.size()])));
throw new IllegalStateException(msg.toString());
@@ -281,6 +294,6 @@ public class AnnotProxyFieldValueFactory
*/
public boolean supportsField(final Field field)
{
- return field.isAnnotationPresent(SpringBean.class);
+ return field.isAnnotationPresent(SpringBean.class) ||
field.isAnnotationPresent(Inject.class);
}
}
Modified:
wicket/trunk/wicket-spring/src/test/java/org/apache/wicket/spring/injection/annot/AnnotProxyFieldValueFactoryTest.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-spring/src/test/java/org/apache/wicket/spring/injection/annot/AnnotProxyFieldValueFactoryTest.java?rev=1221201&r1=1221200&r2=1221201&view=diff
==============================================================================
---
wicket/trunk/wicket-spring/src/test/java/org/apache/wicket/spring/injection/annot/AnnotProxyFieldValueFactoryTest.java
(original)
+++
wicket/trunk/wicket-spring/src/test/java/org/apache/wicket/spring/injection/annot/AnnotProxyFieldValueFactoryTest.java
Tue Dec 20 11:11:11 2011
@@ -24,6 +24,7 @@ import org.apache.wicket.spring.SpringBe
import org.apache.wicket.spring.injection.util.Bean;
import org.apache.wicket.spring.injection.util.Bean2;
import org.apache.wicket.spring.injection.util.Injectable;
+import org.apache.wicket.spring.injection.util.InjectableInterface;
import org.apache.wicket.spring.test.ApplicationContextMock;
import org.junit.Assert;
import org.junit.Test;
@@ -50,7 +51,20 @@ public class AnnotProxyFieldValueFactory
}
};
- Injectable obj = new Injectable();
+ final InjectableInterface obj;
+
+ /**
+ * Construct.
+ */
+ public AnnotProxyFieldValueFactoryTest()
+ {
+ this(new Injectable());
+ }
+
+ protected AnnotProxyFieldValueFactoryTest(InjectableInterface
injectable)
+ {
+ obj = injectable;
+ }
AnnotProxyFieldValueFactory factory = new
AnnotProxyFieldValueFactory(mockCtxLocator);
Added:
wicket/trunk/wicket-spring/src/test/java/org/apache/wicket/spring/injection/annot/JavaxInjectAnnotProxyFieldValueFactoryTest.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-spring/src/test/java/org/apache/wicket/spring/injection/annot/JavaxInjectAnnotProxyFieldValueFactoryTest.java?rev=1221201&view=auto
==============================================================================
---
wicket/trunk/wicket-spring/src/test/java/org/apache/wicket/spring/injection/annot/JavaxInjectAnnotProxyFieldValueFactoryTest.java
(added)
+++
wicket/trunk/wicket-spring/src/test/java/org/apache/wicket/spring/injection/annot/JavaxInjectAnnotProxyFieldValueFactoryTest.java
Tue Dec 20 11:11:11 2011
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.spring.injection.annot;
+
+import org.apache.wicket.spring.injection.util.JavaxInjectable;
+
+
+/**
+ * Tests for javax.inject.Inject when used with spring
+ */
+public class JavaxInjectAnnotProxyFieldValueFactoryTest extends
AnnotProxyFieldValueFactoryTest
+{
+ /**
+ * Construct.
+ */
+ public JavaxInjectAnnotProxyFieldValueFactoryTest()
+ {
+ super(new JavaxInjectable());
+ }
+}
Modified:
wicket/trunk/wicket-spring/src/test/java/org/apache/wicket/spring/injection/util/Injectable.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-spring/src/test/java/org/apache/wicket/spring/injection/util/Injectable.java?rev=1221201&r1=1221200&r2=1221201&view=diff
==============================================================================
---
wicket/trunk/wicket-spring/src/test/java/org/apache/wicket/spring/injection/util/Injectable.java
(original)
+++
wicket/trunk/wicket-spring/src/test/java/org/apache/wicket/spring/injection/util/Injectable.java
Tue Dec 20 11:11:11 2011
@@ -24,7 +24,7 @@ import org.apache.wicket.spring.injectio
* @author Igor Vaynberg (ivaynberg)
*
*/
-public class Injectable
+public class Injectable implements InjectableInterface
{
private Bean nobean;
Added:
wicket/trunk/wicket-spring/src/test/java/org/apache/wicket/spring/injection/util/InjectableInterface.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-spring/src/test/java/org/apache/wicket/spring/injection/util/InjectableInterface.java?rev=1221201&view=auto
==============================================================================
---
wicket/trunk/wicket-spring/src/test/java/org/apache/wicket/spring/injection/util/InjectableInterface.java
(added)
+++
wicket/trunk/wicket-spring/src/test/java/org/apache/wicket/spring/injection/util/InjectableInterface.java
Tue Dec 20 11:11:11 2011
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.spring.injection.util;
+
+public interface InjectableInterface
+{
+ /**
+ * @return test bean
+ */
+ Bean getNobean();
+
+ /**
+ * @return test bean
+ */
+ Bean2 getBeanByName();
+
+ /**
+ * @return test bean
+ */
+ Bean getBeanByClass();
+}
Added:
wicket/trunk/wicket-spring/src/test/java/org/apache/wicket/spring/injection/util/JavaxInjectable.java
URL:
http://svn.apache.org/viewvc/wicket/trunk/wicket-spring/src/test/java/org/apache/wicket/spring/injection/util/JavaxInjectable.java?rev=1221201&view=auto
==============================================================================
---
wicket/trunk/wicket-spring/src/test/java/org/apache/wicket/spring/injection/util/JavaxInjectable.java
(added)
+++
wicket/trunk/wicket-spring/src/test/java/org/apache/wicket/spring/injection/util/JavaxInjectable.java
Tue Dec 20 11:11:11 2011
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.spring.injection.util;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+/**
+ * Mock for an object with some SpringBean annotations
+ *
+ * @author Igor Vaynberg (ivaynberg)
+ *
+ */
+public class JavaxInjectable implements InjectableInterface
+{
+ private Bean nobean;
+
+ @Inject
+ private Bean beanByClass;
+
+ @Inject
+ @Named("somebean")
+ private Bean2 beanByName;
+
+ /**
+ * @return test bean
+ */
+ public Bean getBeanByClass()
+ {
+ return beanByClass;
+ }
+
+ /**
+ * @return test bean
+ */
+ public Bean2 getBeanByName()
+ {
+ return beanByName;
+ }
+
+ /**
+ * @return test bean
+ */
+ public Bean getNobean()
+ {
+ return nobean;
+ }
+
+}