I am developing a Consumer Service for some Webservice.
The application is already providing Webservices (as a server), but this is the first consumer.
The generation is ok, but I encounter a weird -to me!- problem as soon as I try to instantiate the javax.xml.ws.Service from the constructor of a consumer service : all provider webservices implementor bean become suddenly "undefined" (if I comment the first provider from cxf.xml, the second one is also 'undefined' as well).
Looks like I trigger some unexpected injection that may happen too soon... but I don't understand why, and how to fix it! Any idea is welcome!
The error trace :
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'someService' defined in class path resource [spring-core-context.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.my.services.impl.com.my.services.impl.SomeServiceImpl]: Constructor threw exception; nested exception is java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'someProviderWebService': Cannot resolve reference to bean 'someProviderWebServiceImplementor' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'someProviderWebServiceImplementor' is defined
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:254)
...
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.my.services.impl.com.my.services.impl.SomeServiceImpl: Constructor threw exception; nested exception is java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'someProviderWebService': Cannot resolve reference to bean 'someProviderWebServiceImplementor' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'someProviderWebServiceImplementor' is defined
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:115)
...
Caused by: java.lang.RuntimeException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'someProviderWebService': Cannot resolve reference to bean 'someProviderWebServiceImplementor' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'someProviderWebServiceImplementor' is defined
at org.apache.cxf.bus.spring.SpringBusFactory.createBus(SpringBusFactory.java:97)
...
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'someProviderWebService': Cannot resolve reference to bean 'someProviderWebServiceImplementor' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'someProviderWebServiceImplementor' is defined
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275)
...
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'someProviderWebServiceImplementor' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:387)
...
(last)
the cxf.xml
<jaxws:endpoint
id="someProviderWebService"
implementor="#someProviderWebServiceImplementor"
address="/services/SomeProviderWebService"/>
<jaxws:endpoint
id="someProviderWebService2"
implementor="#someProviderWebServiceImplementor2"
address="/services/SomeProviderWebService2"/>
<bean id="logInbound" class="org.apache.cxf.interceptor.LoggingInInterceptor" />
<bean id="logOutbound" class="org.apache.cxf.interceptor.LoggingOutInterceptor" />
<cxf:bus>
<cxf:inInterceptors><ref bean="logInbound" /></cxf:inInterceptors>
<cxf:outInterceptors><ref bean="logOutbound" /></cxf:outInterceptors>
<cxf:inFaultInterceptors><ref bean="logInbound" /></cxf:inFaultInterceptors>
<cxf:outFaultInterceptors><ref bean="logOutbound" /></cxf:outFaultInterceptors>
</cxf:bus>
The someServiceImpl:
public SomeServiceImpl() throws MalformedURLException {
SomeConsumerService service= new SomeConsumerService (); // this is the line causing the problem
}
The webService SomeConsumerService :
public class SomeConsumerService extends javax.xml.ws.Service{
public final static URL WSDL_LOCATION;
public final static QName SERVICE = new QName("urn:test.com:anywhere/webservice/T", "SomeService");
static {
URL url = null;
try {
url = new URL("http://some.wsdl");
} catch (MalformedURLException e) {
System.err.println("Ooops! ");
}
WSDL_LOCATION = url;
}
public SomeConsumerService () {
super(WSDL_LOCATION, SERVICE);
}
}
The Context :
<bean name="someService" class="com.my.services.impl.SomeServiceImpl">
</bean>
<bean name="someProviderWebServiceImplementor" class="com.my.services.impl.SomeProviderWebServiceImplementorImpl">
</bean>
A workmate managed to find out the problem : looks like the cxf servlet will create its own context based on cxf.xml (only!) when it is present. If it is not, it will look for its configuration in application Context.
Though, it also it is only true when I create a consumer... thus, I am not sure whether it is more of an unexpected side-effect, or a true feature.
Anyway, the solution that works here is :
rename cxf.xml to another_name_for_cxf.xml
import the renamed file from application-context.xml (or whatever name you gave it)
<import resource="classpath:another_name_for_cxf.xml"/>
And then, the magic will start to operate!
Related
I have the following value configured in my SQS Listener in springboot. The queue is configured only for DEV and STAGE environments. So I want to disable it in my local after testing. How do i achieve that?
#SqsListener(value = { "${cloud.aws.endpoint}" } , deletionPolicy =SqsMessageDeletionPolicy.ON_SUCCESS)
public void processMessage(String message) throws Exception {
}
I tried to add the following to my application-local.xml(to keep it local), but it didn't work. Anyone went through the same scenario?
autoconfigure:
exclude:
- org.springframework.cloud.aws.autoconfigure.messaging.MessagingAutoConfiguration
- org.springframework.cloud.aws.autoconfigure.context.ContextStackAutoConfiguration
- org.springframework.cloud.aws.autoconfigure.context.ContextRegionProviderAutoConfiguration
I am getting the following error everytime.
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'stackResourceRegistryFactoryBean' defined in class path resource [org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfiguration.class]: Unsatisfied dependency expressed through method 'stackResourceRegistryFactoryBean' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'autoDetectingStackNameProvider' defined in class path resource [org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.aws.core.env.stack.config.StackNameProvider]: Factory method 'autoDetectingStackNameProvider' threw exception; nested exception is java.lang.IllegalArgumentException: No valid instance id defined
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:799) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]
com.amazonaws.SdkClientException: Failed to connect to service endpoint:
at com.amazonaws.internal.EC2ResourceFetcher.doReadResource(EC2ResourceFetcher.java:100) [aws-java-sdk-core-1.11.867.jar:na]
Caused by: java.net.ConnectException: Host is down (connect failed)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'autoDetectingStackNameProvider' defined in class path resource [org/springframework/cloud/aws/autoconfigure/context/ContextStackAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.aws.core.env.stack.config.StackNameProvider]: Factory method 'autoDetectingStackNameProvider' threw exception; nested exception is java.lang.IllegalArgumentException: No valid instance id defined
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:657) ~[spring-beans-5.2.12.RELEASE.jar:5.2.12.RELEASE]
at org.sprin
I've faced similar issues while using #SqsListener. What I usually do is comment out the annotation when running the app locally - it's ugly but it works.
#RepositoryRestResource(path = "/region", collectionResourceRel = "list", excerptProjection = CustomRegion.class)
public interface RegionRepository extends JpaRepository<Region, Integer> {
}
data rest class
#SpringBootApplication
public class ProfUzApplication {
public static void main(String[] args) {
SpringApplication.run(ProfUzApplication.class, args);
}
}
main running class
Occured error
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'repositorySearchController' defined in URL [jar:file:/C:/Users/saidk/.m2/repository/org/springframework/data/spring-data-rest-webmvc/3.2.1.RELEASE/spring-data-rest-webmvc-3.2.1.RELEASE.jar!/org/springframework/data/rest/webmvc/RepositorySearchController.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityLinks' defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.rest.webmvc.support.RepositoryEntityLinks]: Factory method 'entityLinks' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resourceMappings' defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.rest.core.mapping.RepositoryResourceMappings]: Factory method 'resourceMappings' threw exception; nested exception is java.lang.IllegalStateException: Path /region configured for uz.pdp.prof.repository.RegionRepository must only contain a single path segment!
You have to mention path='endpoint name' without using '/' in #RepositoryRestResource. You have to use #RepositoryRestResource(path = "region"), it's direct spring MVC to create RESTful endpoints at /region
The problem is happening because you defined the path using "/". Spring does not allow us to define a composed path like "/api/v1/my_entity". Just remove the "/" from your path and it will work.
I created a new project based on 2.2.2 a couple days ago and got the same issue.
After a few tries, the way to fix it is to use the same value in path and collectionResourceRel. In your case, try to use "region" in both path and collectionResourceRel.
I have a java application in which one of the classes has ContextRefresher autowired:
public abstract class AbstractConfigurationPersister implements IConfigurationPersister {
#Autowired
private ContextRefresher contextRefresher;
#Override
public void forceRefresh() {
contextRefresher.refresh();
}
}
This autowired bean is giving me problems as from the logs, it says that paramater 1 has an unsatisfied dependency.
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration$DataSourceTransactionManagerConfiguration':
Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'application':
Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name
'ktc.tanalytics.prediction.PredictionBeanConfiguration':
Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'configurationService' defined in ktc.tanalytics.commons.CommonsBeanConfiguration:
Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'zookeeperConfigurationPersister' defined in ktc.tanalytics.commons.CommonsBeanConfiguration:
Initialization of bean failed; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'contextRefresher' defined in class path resource [org/springframework/cloud/autoconfigure/RefreshAutoConfiguration.class]:
Unsatisfied dependency expressed through method 'contextRefresher' parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'refreshScope':
Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'org.springframework.transaction.config.internalTransactionAdvisor'
defined in class path resource [org/springframework/transaction/annotation/ProxyTransactionManagementConfiguration.class]:
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [org.springframework.transaction.interceptor.BeanFactoryTransactionAttributeSourceAdvisor]:
Factory method 'transactionAdvisor' threw exception; nested exception is java.lang.NullPointerException
Now, I have checked the code of ContextRefresher in spring (https://github.com/spring-cloud/spring-cloud-commons/blob/master/spring-cloud-context/src/main/java/org/springframework/cloud/context/refresh/ContextRefresher.java) and it receives two arguments.
I suppose that Spring is responsible of creating this ContextRefresher object since it is basically #Autowired. However I do not know why parameter 1 is missing as the log says
Factory method 'transactionAdvisor' threw exception; nested exception is java.lang.NullPointerException
As I focus on the above nested exception, probably transactionAdvisor
is a factory method which tries to create something and while
creating, it is performing some operation on null object.
Just inspect or debug the method: transactionAdvisor , in your code.
So I've been following the Spring documentation, specifically this part,
http://static.springsource.org/spring/docs/current/spring-framework-reference/html/beans.html#beans-factory-collaborators on Dependency Injection, but whenever my code runs, I get an error about bean creation.
Here is portion of my code that I tried to base off the ExampleBean example,
public class TimeFeedHandler implements MessageListener {
String msgID = null;
TimeBayeuxService timeBayeuxService;
public void setTimeBayeuxService(TimeBayeuxService timeBayeuxService) {
this.timeBayeuxService = timeBayeuxService;
}
And my Spring XML file looks like this,
<!-- A POJO that implements the JMS message listener -->
<bean id="timeFeedHandler" class="com.example.streaming.time.TimeFeedHandler" >
<property name="timeBayeuxService" ref="timeBayeuxService"> </property>
</bean>
The error I get is,
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'timeFeedHandler' defined in URL....
Any ideas why or what I'm doing wrong?
Edit, here is the TimeBayeuxService bean,
<!-- Time BayeuxServices -->
<bean id="timeBayeuxService" class="com.example.streaming.time.TimeBayeuxService" lazy-init="true">
<constructor-arg><ref bean="common.bayeux" /></constructor-arg>
<property name="timeBean" ref="time.time" />
</bean>
Here is more of the error. The full error log from STS is wayyyyy too long. I feel like I'm not referencing the TimeBayeuxService bean properly but logically I can't seem to see what I'm doing wrong.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'timeFeedHandler' defined in URL [file:/Users/nullpoint/applicationContext.xml]: Cannot resolve reference to bean 'timeBayeuxService' while setting bean property 'timeFeedHandler'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'timeBayeuxService' defined in URL [file:/Users/nullpoint/applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.example.streaming.time.TimeBayeuxService]: Constructor threw exception; nested exception is java.lang.NullPointerException
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
Here is a portion of the TimeBayeuxService class
public class TimeBayeuxService {
private Bayeux bayeux;
private static StreamingTimeLogGatherer logGatherer;
String testMsgTS = "This is a test message from the original service";
public TimeBayeuxService(Bayeux bayeux) extends SomeBayeuxService{
super(bayeux, TimeBayeuxService.class.getName());
this.bayeux = bayeux;
final Bayeux fbayeux = bayeux;
this.logGatherer = logGatherer;
LogServlet.addLogGatherer(logGatherer);
startThread(fbayeux, testMsgTS, true);
}
timeFeedHandler has a dependency on timeBayeuxService. It can't initialize timeBayeuxService due to NullPointerException so spring can't inject the bean.
According to the error message the NullPointerException happened in the constructor of com.example.streaming.time.TimeBayeuxService. How are you creating common.bayeux bean? Please paste the constructor code for TimeBayeuxService class. Is it an interface? Then you should put the implementation class in the bean definition.
The possible places for NPE. Without the complete stack trace I have to guess the following lines of code:
It can happen inside the constructor of the super class.
These 2 methods: LogServlet.addLogGatherer(logGatherer); startThread(fbayeux, testMsgTS, true);
Using grails 1.1.1
I got this message when I did a modification on a service and then tried to refresh the page.
I have a controller name ContributionPlanController.
It has a service ContributionPlanservice.
inside the ContributionPlanService, it has ProductService and some other Services including JointPIAService.
JointPIAService it self, inherited from ProductService
I did a modification on ProductService, like println on something and this errors always appeared. If I restarted the application, it will works fine.
Any idea how to solve this ?
=========================================================================================
Message: Could not initialize class
JointPIAService$$EnhancerByCGLIB$$e27c7697
Caused by: Error creating bean with
name 'ContributionPlanController':
Initialization of bean failed; nested
exception is
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name
'contributionPlanService': Cannot
create inner bean '(inner bean)' while
setting bean property 'target'; nested
exception is
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name '(inner
bean)#21': Initialization of bean
failed; nested exception is
org.springframework.beans.factory.BeanCreationException:
Error creating bean with name
'jointPIAService': Invocation of init
method failed; nested exception is
org.springframework.aop.framework.AopConfigException:
Could not generate CGLIB subclass of
class [class JointPIAService]: Common
causes of this problem include using a
final class or a non-visible class;
nested exception is
net.sf.cglib.core.CodeGenerationException:
java.lang.reflect.InvocationTargetException-->null
Class: Unknown At Line: [-1] Code
Snippet:
Stack Trace :
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ContributionPlanController': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contributionPlanService': Cannot create inner bean '(inner bean)' while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#21': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jointPIAService': Invocation of init method failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class JointPIAService]: Common causes of this problem include using a final class or a non-visible class; nested exception is net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
at java.security.AccessController.doPrivileged(Native Method)
at org.jsecurity.web.servlet.JSecurityFilter.doFilterInternal(JSecurityFilter.java:382)
at org.jsecurity.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:180)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'contributionPlanService': Cannot create inner bean '(inner bean)' while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#21': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jointPIAService': Invocation of init method failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class JointPIAService]: Common causes of this problem include using a final class or a non-visible class; nested exception is net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
at java.security.AccessController.doPrivileged(Native Method)
... 3 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#21': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jointPIAService': Invocation of init method failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class JointPIAService]: Common causes of this problem include using a final class or a non-visible class; nested exception is net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
at java.security.AccessController.doPrivileged(Native Method)
... 4 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jointPIAService': Invocation of init method failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class JointPIAService]: Common causes of this problem include using a final class or a non-visible class; nested exception is net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
at java.security.AccessController.doPrivileged(Native Method)
... 5 more
Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class JointPIAService]: Common causes of this problem include using a final class or a non-visible class; nested exception is net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
... 6 more
Caused by: net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
at net.sf.cglib.proxy.Enhancer.setCallbacksHelper(Enhancer.java:622)
at net.sf.cglib.proxy.Enhancer.setThreadCallbacks(Enhancer.java:609)
at net.sf.cglib.proxy.Enhancer.createUsingReflection(Enhancer.java:631)
at net.sf.cglib.proxy.Enhancer.firstInstance(Enhancer.java:538)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:231)
at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:285)
... 6 more
Caused by: java.lang.reflect.InvocationTargetException
at net.sf.cglib.proxy.Enhancer.setCallbacksHelper(Enhancer.java:616)
... 12 more
Caused by: java.lang.NoClassDefFoundError: Could not initialize class JointPIAService$$EnhancerByCGLIB$$e27c7697
... 13 more
==========================================================================================
When you declared ContributionPlanService within ContributionPlanController, did you do so with explicit typing ("ContributionPlanService contributionPlanService") or with dynamic typing ("def contributionPlanService")?
In 1.0.4, the combination of auto-wiring and hot swapping only worked with dynamic typing (def ...). That is, that an explicitly declared service would get auto-wired okay the first time you start up the app, but that the hot swapping is foiled thereafter. Changing the declaring to def would make the hot swapping work, but then you lose the benefit of your IDE helping you out.
Now that you mention it, I was hoping this would be fixed in 1.1.x, but I haven't tried it yet. (I'm not in a position to test it right this moment, but I didn't want to wait to send you this answer. Try it and let me know.)