Class path resource not found randomly - java

We have integrated Spring with Hibernate and Struts2 in Eclipse and have been getting these errors when running the build:
14-Oct-2011 10:37:27 org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: class path resource [Test.hbm.xml] cannot be opened because it does not exist
...
Caused by: java.io.FileNotFoundException: class path resource [Test.hbm.xml] cannot be opened because it does not exist
...
Our mapping in applicationContext.xml is:
<property name="mappingResources" value="Test.hbm.xml" />
Test.hbm.xml is in /build/classes, and we have tried putting it in /WEB-INF, /src, and even created a new source folder called /hibernate and dumped it in and it worked on only a few machines.
The first time we wrote it, it showed this error. And then we copied the exact same code into a new project, it suddenly worked. On some machines, it works; on others, it shows this error.
Does anyone know what could be wrong? Let me know if any other information is needed.
Thanks so much.

That's not a build-time error. It's a run-time one. Intermittent failures of that sort indicate a problem with your build, though. As a classpath resource, Test.hbm.xml must be in a classpath location when you run your app. Where exactly that is depends on how you're running it, but /WEB-INF will never work for a webapp, and a random /hibernate folder is unlikely to work, too, unless you've done some custom configuration to make that a classpath resource or make it build to one. For a more definitive answer, you'll need to provide more detail about what you're running and how you're building it.

Related

Not able to run java EE project

I have an existing java (EE) project, which I am trying to run from eclipse. I have imported that project in eclipse and added the tomcat7 server. But when I am running the project, it is giving spring error as
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'seoDestinationsDataSource' defined in class path resource [spring/fn-landing-persistence-context.xml]: Could not resolve placeholder 'seodestinations.db.driverClassName' in string value "${seodestinations.db.driverClassName}"
Please find below snapshot of error.
Image
What is the step i am missing. Please advise. Thanks for help.

Deploying spring application in wildfly 11 result in " Only one AsyncAnnotationBeanPostProcessor may exist within the context." error

We have a Java Spring 3.2 project, we are trying to migrate the project from jBoss 7 to wildFly 11
However, during the deployment the following error occurs:
Cannot upload deployment: {"WFLYCTL0080: Failed services" => {"jboss.undertow.deployment.default-server.default-host./faultmanager" =>
"java.lang.RuntimeException: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem:
Only one AsyncAnnotationBeanPostProcessor may exist within the context. Offending resource:
\"/D:/wildfly-11.0.0.Final/wildfly-11.0.0.Final/bin/content/xxxx.war/WEB-INF/classes/META-INF/spring/applicationContext.xml\"
Caused by: java.lang.RuntimeException: org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: Only one AsyncAnnotationBeanPostProcessor may exist within the context. Offending resource:
\"/D:/wildfly-11.0.0.Final/wildfly-11.0.0.Final/bin/content/xxxxxx.war/WEB-INF/classes/META-INF/spring/applicationContext.xml\"
Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem:
Only one AsyncAnnotationBeanPostProcessor may exist within the context. Offending resource:
\"/D:/wildfly-11.0.0.Final/wildfly-11.0.0.Final/bin/content/xxxxxx.war/WEB-INF/classes/META-INF/spring/applicationContext.xml\""}}
With our attempts and our searches, we got that the exception could be throwed by some causes:
Some bean in applicationContext.xml is defined twice
The applicationContext.xml is imported twice
Some bean defined in applcationContext.xml is defined again in a different file
This may be caused by a tag defined in applicationElement.xml, but trying to remove it will cause a illegalArgumentException during the deploy (don't know why), interestingly this doesn't appear to be used anywhere
This may be caused by another contextl (we have an applicationContext-security) but even removing it the same error above will persist
Others fun facts:
The error is never throwned during the build, only during the deploy throught wildFly
The same project have worked for year in jboss without this kind of problem
What could be the cause?
this will happens only ,
1)may be you are import both applicationContext-root.xml and applicationContext-where-annotation-driven-is-specififed.xml in your WEB.xml in section.
2)make applicationContext-root.xml in WEB.xml.
2)This is happenning because you are initializ The application context twice but org.springframework.scheduling.config.AnnotationDrivenBeanDefinitionParser fails registering bean ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME second time.
3)and spring parses the <task:annotation-driven/> text twice in a config XML.
may be one of the resons is that #ContextConfiguration("/path/to/applicationContext.xml") are both the parent test class and child test class

ConflictingBeanDefinitionException even after deleting a class

I am developing a simple maven + spring application and i am getting the following error. It says two of my classes have a conflict. so i deleted the second class but i am still getting the same error. I tried restarting the server but it still says my class exists. Can somebody help?
Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.nibm.config.RootConfig]; nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'employeeController' for bean class [com.nibm.hibernate.controller.EmployeeController] conflicts with existing, non-compatible bean definition of same name and class [com.nibm.controller.EmployeeController]
I was able to solve a similar problem by using IntelliJ's function "Rebuild".
The reason was an orphan .class file after the corresponding .java file had already been deleted.
You get the exception because you have two spring beans of the same class.
This exception is thrown by
org.springframework.context.annotation.ClassPathBeanDefinitionScanner#isCompatible
And looking at that implementation it looks as if you create a bean of type EmployeeController in your RootConfig and additionally by ComponentScan.
To fix the problem remove the bean from the RootConfig or change your ComponentScan, so this bean is not found by it.
You can set a breakpoint in the constructor of EmployeeController. From the stack you can get more information about how and why the bean is created.
I faced the same problem and it was because class with same name exist at two locations as mentioned in the Exception itself which are conflicting and after removing one issue got fixed.
I was getting this same ConflictingBeanDefinitionException..."conflicts with existing, non-compatible bean definition of same name and class" when running JUnit tests with #RunWith(SpringRunner.class)/ #SpringBootTest from inside Intellij.
Execution via gradle:build of the same tests were running fine.
This began to happen after I had refactored the packaging of several #Components which lead me to believe something was holding a reference to the class under it's previous package name.
No amount of gradle build/clean would seem to clear it.
Doing a Build -> Rebuild Project in IntelliJ was what cleared this issue for me.

NoClassDefFoundError Using Hibernate

I'm using Spring 3.1.1.RELEASE and Hibernate 4.1.10.FINAL in a Building Block on Blackboard Learn and getting the following exception:
java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.cfg.PropertyContainer
This seems to be a classpath issue, and so I did some digging and added the suggested libraries from this post but the same error occurs.
So my classpath now contains the necessary dependencies, but I am still getting the exception. What are some additional points I can look at to identify and resolve this issue?
Edit: I've verified the jboss-logging JAR is in my classpath.
Edit: Requested Stack Trace: https://gist.github.com/whargrove/79cbc9c5bd65217e3da3
After restarting Tomcat and re-deploying my WAR the following exceptions are observed in the Tomcat logs:
java.security.AccessControlException: access denied ("java.util.PropertyPermission" "jboss.i18n.generate-proxies" "write")
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in ServletContext resource [/WEB-INF/config/spring.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class org.hibernate.cfg.PropertyContainer
(Full stack trace available in gist link above.)
The message
java.lang.NoClassDefFoundError: Could not initialize class SomeClass
means that the JVM has already tried and failed to perform static initialization on the class SomeClass. There may well be another error which happened earlier on when the JVM tried to load the class the first time.
Taking a look at the source of the PropertyContainer class, the only static intialization is a static initializer that sets a system property, and a line that initializes a logger for the class. Setting a system property will should not cause a problem, so my guess is that the logger class used is missing from your classpath.
The logger class used is org.jboss.logging.Logger. A quick Google for this class suggested a jar named jboss-logging.jar. Try getting a copy of that and adding it to your classpath.
(Incidentally, if you can't find a previous error before the 'Could not initialize class' error, that may well be because the missing JAR affects logging. Logging is something applications tend to assume is always working and can be used everywhere. The exception you are seeing might have been thrown from within a finally block that tried to do some logging when the corresponding try block also tried to do some logging but threw an exception. An exception thrown from within a finally block replaces any exception that had previously been thrown.)
EDIT in response to the stacktrace: I can now see that I was wrong about setting a system property not being the problem! I don't know the first thing about Blackboard Learn, but it is possible that it or something else has tightened up the security in your application and hence caused the above problem.
It does however confirm my belief that the real cause of the problem was before the Could not initialize class message.

Tomcat - unable to open logs - unable to deploy

I am trying to deploy a web app on an Ubuntu system. The WAR is an EXPLODED folder. There are no issues with build. But I am unable to deploy to Tomcat6 server. Everything was working fine. Same Code, Same files. All of a sudden, unable to deploy.
The main difference I find now is that - the logs at /var/lib/tomcat6/logs - localhost.2010-11-01.log is locked and can be opened only by root user. Dont understand why?
Because of this issue, I am getting the following error (from localhost.2010-11-01.log):
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
Is my issue related to
BeanCreationException in Spring Framework .WAR deploy to Tomcat 6 on Ubuntu 9.10?
Update1:
The issue of Tomcat logs being readable by root user is gone now. However, these ERRORs remain.
SEVERE: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'africa' defined in ServletContext resource [/WEB-INF/applicationContext.xml]:
Cannot resolve reference to bean 'antarctica' while setting bean property 'antarctica'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'antarctica' defined in ServletContext resource [/WEB-INF/applicationContext.xml]:
Cannot resolve reference to bean 'australia' while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'australia' defined in ServletContext resource [/WEB-INF/applicationContext.xml]:
Invocation of init method failed; nested exception is java.lang.Exception: Unexpected line
Warning: mysql_connect(): Lost connection to MySQL server during query in .... #ERROR:Too Many Connections!
Update 2:
Just switched on my Ubuntu system. Only firefox running at the moment. No Eclipse or other software running. Did not shutdown or restart Tomcat. Just tried to launch the web app thru Tomcat Manager application (http://localhost:8080/manager/html) - the same thing I had been trying before.
Result: Web app gets launched with no issues!
I have absolutely NO CLUE why this did not work before. Also, NO CLUE why it's working now, if at all there was a serious issue. I WASTED one whole day :(.
if you set-up logging like so: Tomcat startup logs - SEVERE: Error filterStart how to get a stack trace?
Then at least you will get the stack trace.

Categories

Resources