spring framework Error: Context initialization failed - spring

i am deploying application(spring-hibernate) in tomcat6 but it is giving error-
ERROR org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to load bean class: com.myPackage.myProject.calendar.bpo.BusinessDirectoryBPOImpl; nested exception is java.io.FileNotFoundException: class path resource [com/myPackage/framework/bpo/BaseBPOImpl.class] cannot be opened because it does not exist
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:180)
......
all jar files are already in \WEB-INF\lib*.jar.
am i missing any class file or any jar file.
how to solve this error.
Thanks
Yugal

com.myPackage.myProject.calendar.bpo.BusinessDirectoryBPOImpl is looking for
com/myPackage/framework/bpo/BaseBPOImpl.class
which it cannot find.
Check for sure if this specific class is present under WEB-INF\lib in a jar or WEB-INF\classes as a class file.

Related

Cannot find properties file in class path - Error while deploying EAR

Getting the following ERROR while trying to deploy a EAR project in JBoss AS 7.
(MSC service thread 1-5) Context initialization failed. java.io.FileNotFoundException: class path resource [.properties] cannot be opened because it does not exist
A more detailed snapshot of the errors is given below.
16:20:08,548 ERROR [org.springframework.web.servlet.DispatcherServlet]
(MSC service thread 1-5) Context initialization failed:
org.springframework.beans.factory.BeanDefinitionStoreException:
Failed to parse configuration class [xx.xx.Config]; nested exception
is java.io.FileNotFoundException: class path resource
[wwwr.properties] cannot be opened because it does not exist at
org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:181)
[spring-context-4.2.1.RELEASE.jar:4.2.1.RELEASE] Caused by:
java.io.FileNotFoundException: class path resource [wwwr.properties]
cannot be opened because it does not exist
16:20:08,588 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/MyWeb]]
(MSC service thread 1-5) StandardWrapper.Throwable:
org.springframework.beans.factory.BeanDefinitionStoreException: Failed
to parse configuration class [com.xx.Config]; nested exception is
java.io.FileNotFoundException: class path resource [wwwr.properties]
cannot be opened because it does not exist
I am using JBoss AS7 server and MyEclipse as IDE.
Well I found the solution to be involving the following steps
1) Make sure that the property file is in the Class Path of the projects involved or at least in the modules deployed in Jboss.
1- a) Verify that the modules.xml file has the right entries
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="com.xx.yy">
<resources>
<resource-root path="./properties/"/>
2) Verify that the Manifest.mf file in the EAR has the required dependencies.
Dependencies: com.xx.yy
3) Clean build and Deploy to server.

Spring import resource: Skip if file does not exist

I added this to my Spring configuration inside my WAR file:
<import resource="classpath:myapp-custom-settings.xml"/>
This way, users can create a myapp-custom-settings.xml file (in a folder listed in shared.loader) to modify the beans they want without having to unzip the WAR.
Very convenient, but most users don't have such a file, in which case a FileNotFoundException happens and the app does not start:
ERROR: org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:Configuration problem: Failed to import bean definitions from URL location [file:/home/nico/tomcat/conf/myapp-custom-settings.xml]
Offending resource: ServletContext resource [/WEB-INF/spring/root-context.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from URL [file:/home/nico/tomcat/conf/myapp-custom-settings.xml]; nested exception is
java.io.FileNotFoundException: /home/nico/tomcat/conf/myapp-custom-settings.xml (No such file or directory)
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:70)
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:233)
QUESTION: Is there a way to make this import failsafe?
I mean, load the file if it exists, but skip if it does not exist.
The trick is to use classpath* instead of classpath. Note the * asterisk character.
Example:
<import resource="classpath*:myapp-custom-settings.xml"/>
The app will now start normally even if no myapp-custom-settings.xml file is found.

Can't start application in IDE with <jar-find> error, but 'gradle bootRun' - works fine

So, i have a problem that can't solve.
I have a multi module gradle project with spring boot runners. With Jpa, Elastic, OrientDb and another configurations provided by spring-data and spring-integration. And i try to start my web application! Write web starter, make annotation scan, so when I use task 'gradle bootRun' - everything start perfectly - app works, all contexts up and life is good.BUT, when i try use my favorite IDE like Intellij idea, or colleague use Eclipse - get an error :
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with
name 'org.springframework.integration.config.IdGenerato rConfigurer#0':
BeanPostProcessor before instantiation of bean failed; nested exception is
org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with
name org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration':
Initialization of bean failed; nested exception is java.lang.NoSuchMethodError:
org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration.setBeanFactory(Lo rg/springframework/beans/factory/BeanFactoryV
That cause by (projectName - is fake):
java.lang.RuntimeException: error trying to scan <jar-file>:
file:/home/<user>/project/<projectName>/classes/production/<projectName>-system-webapp/
But i have NO /projectName/classes/production/ folder! Anyway - with gradle it's work fine.
And to be honestly, before this another error catched:
Error creating bean with name 'entityManagerFactory' defined in class com.project.system.jpa.PepperJpaConfiguration: Invocation of init method failed
caused by:
error trying to scan <jar-file>: file:/home/<user>/project/<projectName>/classes/production/<projectName>-system-webapp/
Thank you for advice! Can give additional info.
P.S : Edited
So, the problem was solved:
I do not provide important error stacktrace like:
at org.hibernate.ejb.packaging.NativeScanner.getFilesInJar(NativeScanner.java:195)
at org.hibernate.ejb.Ejb3Configuration.addScannedEntries(Ejb3Configuration.java:506)
at org.hibernate.ejb.Ejb3Configuration.scanForClasses(Ejb3Configuration.java:861)
... 21 more
Caused by: java.io.IOException: invalid constant type: 18 at 50
And this was and JDK8-Hibernate-javassist problem https://hibernate.atlassian.net/browse/HHH-8286
When upgrade javassist version to 3.18.1-GA - all problems was solved(but why run through gradle worked perfectly...)

Getting error in trying to read applicationContext.xml in Standalone java

ApplicationContext context=new ClassPathXmlApplicationContext("classpath:applicationContext.xml");
InvGroupDelegate igcd = (InvGroupDelegate) context.getBean("invGroupDelegate");
Giving error:
Caused by: java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:157)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
The appContext file is present in myProject/properties
And this is also added to 'Src folders in the build path'.
Resolved it. Was an eclipse issue. Closed the project and reopned it. Then cleaned up everything and built once more. Then things were fine.

FileNotFound exception thrown when trying to create application-context object using ClassPathXmlApplicationContext on Weblogic server

Scenario
There was a requirement in my project to multi-thread calls made to a Webservice. This is implemented using ThreadPoolTaskExecutor (Spring).
As the thread class required values to be fed at runtime, had implemented the code as below -
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("application-context.xml");
for (DocumentData documentData : documentDataList){
MinerThread minerThread = applicationContext.getBean("minerThread",MinerThread.class);
minerThread.setHeader(header);
minerThread.setDocumentData(documentData);
minerThread.setBatchSize(batchSize);
minerThreadExecutor.execute(minerThread);
}
Issue
In local I have tomcat server and this implementation works as expected. However on Weblogic (on the client machine, I don't have access to Weblogic) when the war is deployed it throws FileNotFound Exception.
As the application context object is created via ClassPathXmlApplicationContext API thought the error was thrown because the location was not under the Weblogic classpath. There was nothing set in the Weblogic server classpath. However even after including WEB-INF/classes in the classpath the same exception is thrown.
Exception
2013/01/29 09:19:12,853 [ERROR] RequestQueueListener - org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [../shared-common-context.xml]
Offending resource: class path resource [application-context.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [../shared-common-context.xml]; nested exception is java.io.FileNotFoundException: class path resource [../shared-common-context.xml] cannot be opened because it does not exist
BeanDefinitionParsingException is caused because of the relative path that was added in the Weblogic classpath.
On the Weblogic the file is at the location -
./wls10.3.4/ColorisPPT1/user_projects/domains/Coloris_PPT1_Domain/servers/Coloris_PPT1_AdminServer/tmp/.appmergegen_1336142780924_documentservice.war/WEB-INF/classes
When the war if built (Maven is used) the application-context.xml is placed under WEB-INF/classes folder.
Could someone please suggest how to proceed with this.

Resources