Configuration issue: Failed to import bean definitions from URL location - spring

I am trying to use apache cxf to generate webservice in my Spring project. Everything goes well as I can see generated wsdl file and other files but I get org.springframework.beans.factory.parsing.BeanDefinitionParsingException.I am not using spring anywhere. So I think that whether generated wsdl is not correct one.
Here are few logs:
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:META-INF/cxf/cxf-extension-soap.xml]
Offending resource: ServletContext resource [/WEB-INF/cxf-beans.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [META-INF/cxf/cxf-extension-soap.xml]; nested exception is java.io.FileNotFoundException: class path resource [META-INF/cxf/cxf-extension-soap.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:76)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinitionDocumentReader.java:256)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement(DefaultBeanDefinitionDocumentReader.java:207)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:192)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:139)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:108)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)

cxf-beans.xml is spring configuration metadata which creates bean, manages life cycle and dependenices. Since in your web.xml you have added the contextloader with context param giving location of the cxf-bean.xml, you have switched on spring container on top of which cxf runs.
Coming back to your issue, it seems like you don't have all your dependecies(jars) for your cxf soap service. Since from cxf version 2.3 cxf.xml internally resolves all the required cxf-extension-*.xml and since you are using soap, I believe its searching for cxf-extension-soap.xml which is part of cxf-rt-bindings-soap.jar. Make sure all the cxf dependent jars are loaded

I resolved the above issue using cxf 3.0 and removing the imports for cxf-extesions-*.xml

Related

Couldn't able to retrieve the path of h2 db when spring-boot application being deployed with application jar

I am deploying a spring boot application with jar built by maven, and i am using the h2 db as file which is placed in the resource folder. And i am creating the spring JdbcTemplate connection using the Hikari configuration. Here for Hikari configuration i need to provide the location of the h2 db location as URL and i trying to provide as per the h2 db documentation. But while creating the connection application failed saying following exception
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'h2DBConnection' defined in com.xx.Application: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.jdbc.core.JdbcTemplate]: Factory method 'h2DBConnection' threw exception; nested exception is java.io.FileNotFoundException: class path resource [h2DB.mv.db] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/home/app/app.jar!/BOOT-INF/classes!/h2DB.mv.db
But when i check the jar file to see the content file is there in the mentioned path.
And i saw other posts saying need to use the ResourceLoader with inputstream to load the files from the jar. But here i need to provide the path to db file for Hikari config.
It is working fine in the IDE only issue when i start the application using Jar
Can someone help me how can it be done?
i tried to use the classpathResource and ResourceLoader but it couldn't able to get the file by jdbctemplate.

JNDI resources not available for Gemini Blueprint running in Tomcat 9 (working in Bundle Activator)

I have an older Web-Application using Eclipse RAP 3.0 with Equinox OSGI-Container and Gemini Blueprint 1.0.2.
I can define my JDNI Values in server.xml
link them in context.xml and use them in my web.xml.
In my launch.ini i use the parent classloader fwk so the JNDI configuration is passed to the OSGI-Container.
My Application-Bundles can read those values for example in Bundle-Activator:
String xxx= InitialContext.doLookup("java:comp/env/xxx"); or
String xxx= new InitialContext().lookup("java:comp/env/xxx");
Some Bundle-Configuration is done via Gemini Blueprint xml files and SpringConfiguration Java classes.
<jee:jndi-lookup id="xxx" jndi-name="java:comp/env/xxx" />
This part is not working and i get following error
Error creating bean with name 'xxx': Invocation of init method failed;
nested exception is javax.naming.NameNotFoundException:
Name [java:comp/env/xxx] is not bound in this Context. Unable to find [java:comp].
I get the same Error when i use Spring-Java-Configuration which is invoked from gemini blueprint xml. Then statements like new InitialContext().lookup("java:comp/env/xxx") don't work and i get the same exception.
I think it has to to with the classloaders that are different for Bundle-Activator-Code and Gemini BlueprintExtender Thread but in can't figure it out how to solve this.
I found a Solution that i can use.
If i Move my JNDI-Lookups from xml into my Spring-Configuration-class then i can change the clasloader in init like this:
Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
After that i my Lookups work fine.
i found that solution here
Can Spring Boot be used with OSGi? If not, any plans to have an OSGi Spring Boot?.

java version "1.8.0_121" Requested bean is currently in creation: Is there an unresolvable circular reference?

When I build and deploy my spring based Application with
java version "1.8.0_112" it compiles and deploys fine.
Also, if i compile with java version "1.8.0_121", and deploy with
java version "1.8.0_112" that works too.
But when I compile and deploy the same Application with
java version "1.8.0_121"
it gives me an error for one service:
Error creating bean with name 'namesServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private a.b.c.backend.services.account.PersonService a.b.c.backend.services.serviceimpl.NamesServiceImpl.personService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'CISExpressionHandler' defined in URL
[jar:file:/usr/local/tomcat7-7/webapps/ServicesApp/WEB-INF/lib/E2Services.jar!/META-INF/spring/applicationContext-security.xml]: Cannot resolve reference to bean 'CISPermissionEvaluator' while setting bean property 'permissionEvaluator'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'CISPermissionEvaluator': Requested bean is currently in creation: Is there an unresolvable circular reference?
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private a.b.c.backend.services.ciscase.CaseService a.b.c.backend.services.security.permissionEvaluators.CaseOwnerPermission.caseService; nested exception is org.springframework.beans.factory.BeanCreationException
One explanation, I could find was:
The exception may or may not occur depends on the creation order of beans. We load them with config something like below in web.xml
(/usr/local/tomcat7-7/webapps/ServicesApp/WEB-INF/web.xml)
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:META-INF/spring/applicationContext*.xml</param-value>
</context-param>
The XML files will be loaded by XmlWebApplicationContext class and the loading order of files are not guaranteed.
It just loads files from the file system. The problem is here.
There's no problem if the class loads the application context file first, because your beans are already created when they are used for the construction injection of Spring Security. But, if it loads the Spring Security context file first, the circular reference problem occurs, because Spring tries to use your beans in the constructor injection before they had been created.
How to solve the problem?
Force the loading order of the xml files. loading the security context xml file at the end of the application context file by using
<import resource="applicationContext-security.xml">.
Now how this got introduced with JDK version change? I don't have an explanation for that
ref: Splitting applicationContext to multiple files
Q: How do i get the order of beans at deployment ?

Spring context not found using groovy classloader

I get a typical error, because the spring context could not be found:
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsingXML document from class path resource nested exception is java.io.FileNotFoundException: class path resource cannot be opened because it does not exist
The class creating the spring context is instantiated in a "strange" way. There's a java process, creating a groovy classloader and adding the required classpath entries (including the jar with the spring context). Using this classloader a groovy script will be executed, which in turn executes a java class creating a spring bean in the static init block. Unfortunately this fails with the above exception.
If the initial java process is called with -cp jarContainingContext it works. The jar containing the spring context, also contains the java class creating the spring context. Thus I'm sure that the jar is in the classpath.
Is it possible the the groovy classloader is different from the one of spring (if there's a seperate one)?
java MyClass -> Creates groovy classloader with all required classpath entries -> runscript -> groovy script -> running java class from a library also containing the spring context -> tries to create the bean within the static initializer -> failure
This whole chain sounds quite strange, it is but I can't really change it. I simply cannot understand where the problem is. Because the java class creating the spring context will be found by the groovy classloader but not the springContext within the same jar. It seems like there are 2 seperate classpaths.
The problem are really the classloaders. SpringBatch has a bug and might use the system classloader. Thus a classloader hell is created.
We issued a pull request to fix the issue.

OAUTH2 transaction manager grails mongodb

I am working on an app that uses a mongodb, is built in grails, and is using oauth2 as an authentication service. I have the services and controller built out (I think) and am trying to run my server to manually test connectivity with google. I am running into an "Error creating bean with name transactionManagerPostProcessor..." that I can't solve. I know I need to either install a plug-in that takes care of the "transactions" for me, or create a bean in resources.groovy.
I have done a lot of researching and reading up on this, but I have been at a dead end for the last couple days trying to get this implemented. Can someone tell me how to solve this problem, create the correct bean, or install the correct plug-in? Partial stack trace below, with link to full stack trace:
|Loading Grails 2.3.4
|Configuring classpath
.
|Environment set to development
.................................
|Packaging Grails application
............................................
|Running Grails application
Configuring Spring Security Core ...
... finished configuring Spring Security Core
Error |
2014-01-16 09:30:52,840 [localhost-startStop-1] ERROR context.GrailsContextLoader - Error initializing the application: Error creating bean with name 'transactionManagerPostProcessor': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoTransactionManager': Cannot resolve reference to bean 'mongoDatastore' while setting bean property 'datastore'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoDatastore': Cannot resolve reference to bean 'mongoMappingContext' while setting bean property 'mappingContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mongoMappingContext': FactoryBean threw exception on object creation; nested exception is java.lang.NoClassDefFoundError: org/springframework/format/datetime/DateFormatterRegistrar
Full stacktrace can be found at: http://pastebin.com/5mW5uwtu
I have tried adding
static transaction = 'mongo'
to the service that calls google to authenticate the user. This is a solution I found on a similiar question on stackoverflow. I have also fiddled with different plugins and dependencies in my build-config. Not sure what else there is to try.
Thank you!
To work around this issue with some plugins, I've added the following to the beans block in resources.groovy
// some plugins need a transaction manager,
// although the mongo one isn't properly transactional
// and could produce unexpected results in some cases.
springConfig.addAlias('transactionManager', 'mongoTransactionManager')
However, the specific error you're seeing relates to the Spring class DateFormatterRegistrar not being found. Are you using an up-to-date version of Grails (e.g. 2.3+) and the mongo plugin? Have you added the mongo plugin as a compile plugin dependency in BuildConfig?:
compile ":mongodb:1.3.3"

Resources