spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
56.21k stars 37.98k forks source link

Default autowiring in Spring's test context framework causing problem with CXF [SPR-4939] #9614

Closed spring-projects-issues closed 16 years ago

spring-projects-issues commented 16 years ago

James Kavanagh opened SPR-4939 and commented

I have a spring configured instance of a CXF conduit that I'm using in my integration tests which is causing me a problem. At present I am subclassing AbstractJUnit4SpringContextTests and obtaining my dependencies from the context manually. The problem I'm having is that when I attempt to call a method on my CXF client I get the following exception:

javax.xml.ws.soap.SOAPFaultException: Error creating bean with name '*.http-conduit': Injection of resource methods failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [org.apache.cxf.configuration.security.AuthorizationPolicy] is defined: Unsatisfied dependency of type [class org.apache.cxf.configuration.security.AuthorizationPolicy]: expected at least 1 matching bean at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:211) at $Proxy54.getAccountDetails(Unknown Source) at com.sportex.regpay.payment.mtapi.transfers.TransferFundsIntegrationTest.performTransferCreditSuccessfulWithGBP(TransferFundsIntegrationTest.java:97) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.springframework.test.context.junit4.SpringTestMethod.invoke(SpringTestMethod.java:163) at org.springframework.test.context.junit4.SpringMethodRoadie.runTestMethod(SpringMethodRoadie.java:233) at org.springframework.test.context.junit4.SpringMethodRoadie$RunBeforesThenTestThenAfters.run(SpringMethodRoadie.java:333) at org.springframework.test.context.junit4.SpringMethodRoadie.runWithRepetitions(SpringMethodRoadie.java:217) at org.springframework.test.context.junit4.SpringMethodRoadie.runTest(SpringMethodRoadie.java:197) at org.springframework.test.context.junit4.SpringMethodRoadie.run(SpringMethodRoadie.java:143) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.invokeTestMethod(SpringJUnit4ClassRunner.java:142) at org.junit.internal.runners.JUnit4ClassRunner.runMethods(JUnit4ClassRunner.java:51) at org.junit.internal.runners.JUnit4ClassRunner$1.run(JUnit4ClassRunner.java:44) at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:27) at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:37) at org.junit.internal.runners.JUnit4ClassRunner.run(JUnit4ClassRunner.java:42) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '*.http-conduit': Injection of resource methods failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [org.apache.cxf.configuration.security.AuthorizationPolicy] is defined: Unsatisfied dependency of type [class org.apache.cxf.configuration.security.AuthorizationPolicy]: expected at least 1 matching bean at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:306) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:996) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.configureBean(AbstractAutowireCapableBeanFactory.java:283) at org.springframework.beans.factory.wiring.BeanConfigurerSupport.configureBean(BeanConfigurerSupport.java:155) at org.apache.cxf.configuration.spring.ConfigurerImpl.configureBean(ConfigurerImpl.java:114) at org.apache.cxf.configuration.spring.ConfigurerImpl.configureWithWildCard(ConfigurerImpl.java:134) at org.apache.cxf.configuration.spring.ConfigurerImpl.configureBean(ConfigurerImpl.java:101) at org.apache.cxf.configuration.spring.ConfigurerImpl.configureBean(ConfigurerImpl.java:84) at org.apache.cxf.transport.http.AbstractHTTPTransportFactory.configure(AbstractHTTPTransportFactory.java:223) at org.apache.cxf.transport.http.AbstractHTTPTransportFactory.getConduit(AbstractHTTPTransportFactory.java:163) at org.apache.cxf.transport.http.AbstractHTTPTransportFactory.getConduit(AbstractHTTPTransportFactory.java:145) at org.apache.cxf.endpoint.AbstractConduitSelector.getSelectedConduit(AbstractConduitSelector.java:73) at org.apache.cxf.endpoint.UpfrontConduitSelector.prepare(UpfrontConduitSelector.java:61) at org.apache.cxf.endpoint.ClientImpl.prepareConduitSelector(ClientImpl.java:452) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:273) at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:222) at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73) at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:170) ... 24 more Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [org.apache.cxf.configuration.security.AuthorizationPolicy] is defined: Unsatisfied dependency of type [class org.apache.cxf.configuration.security.AuthorizationPolicy]: expected at least 1 matching bean at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:613) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.getResource(CommonAnnotationBeanPostProcessor.java:423) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor$ResourceElement.getResourceToInject(CommonAnnotationBeanPostProcessor.java:502) at org.springframework.beans.factory.annotation.InjectionMetadata$InjectedElement.inject(InjectionMetadata.java:192) at org.springframework.beans.factory.annotation.InjectionMetadata.injectMethods(InjectionMetadata.java:117) at org.springframework.context.annotation.CommonAnnotationBeanPostProcessor.postProcessPropertyValues(CommonAnnotationBeanPostProcessor.java:303) ... 41 more

The problem is caused because the class in question org.apache.cxf.transport.http.HTTPConduit has the following method declaration: /**

Obviously Spring thinks that it needs to inject this bean because of the @Resource annotation but in actual fact it isn't necessary. I guess what I'm asking is whether there is a way to disable autowiring in this case and if not is there a plan to provide this ability in the near future?

Many thanks, James K


Affects: 2.5.4

spring-projects-issues commented 16 years ago

Juergen Hoeller commented

Arguably this is wrong on CXF's side: Why put an @Resource annotation when this is not an object that must be injected? Why put @Resource there in a framework class in the first place??

I do see value in turning off the default Spring annotation support even in an integration testing environment. However, typically for the purpose of customizing post-processors... not because some third-party framework class happens to have an inappropriate @Resource annotation somewhere.

Juergen

spring-projects-issues commented 16 years ago

James Kavanagh commented

Hi Jeurgen,

I actually raised this with CXF independently and they have now, sensibly, removed the annotation so in effect this is no longer an issue with CXF in the current version.

James

spring-projects-issues commented 16 years ago

Juergen Hoeller commented

Good to hear - kudos to the CXF guys! Closing this issue from Spring's side then...

We might eventually make default autowiring configurable even in the test context framework: possibly in the 3.0 timeframe.

Juergen