FileNotFoundException, although the XML file should be deployed - java

I've got problems starting my WAR application on a local JBoss. After two other EARs are deployed and the TomcatDeployer begins deploying the WAR, I'm getting the following error message:
2010-04-28 10:01:56,605 ERROR [org.jboss.ejb.plugins.LogInterceptor] [] [main] EJBException in method: public abstract [return type] methode throws javax.ejb.CreateException,java.rmi.RemoteException, causedBy:
javax.ejb.EJBException: org.springframework.beans.factory.access.BootstrapException: Unable to initialize group definition. Group resource name [classpath*:context.xml], factory key [contextService]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'service' defined in URL [jar:file:/C:/jboss-4.2.3.GA/server/default/deploy/frontend.war/WEB-INF/lib/modules.jar!/aontext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.context.support.ClassPathXmlApplicationContext]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [package/context.xml]; nested exception is java.io.FileNotFoundException: class path resource [package/context.xml] cannot be opened because it does not exist
But package/context.xml actually is placed inside a JAR in one of my EAR files which should be deployed before the WAR. And at least I get a message that the deployment of the EAR has been successful. I also looked into the JAR with my file archiver and the context.xml is indeed there at the right place.
Is there a way for me to get sure that the JAR, not the EAR as a whole, is really deployed to the JBoss? I'm already starting to lose my head about this issue.
Thank you.
Bernhard

Could be a classloader issue. You can check whether your JAR and its contents are loaded properly by configuring a logger for classloading events, as described here (example 3.8).
The log also gives you information about which classloader loaded what - this might explain why your web app (loaded by its own loader) does not see stuff within the EAR.
Another thing: is the JAR containing the XML file included in the classpath of the WAR?

I have deployed my war in another deploy directory called "deploy.last" in the JBoss directory, since it has to be -- as the name suggests -- deployed at last.
Now I've changed my JBoss configuration and put the war in the higher-ranking deploy directory (where the two EARs are too) and everything is working fine now. The war is still deployed at last.
I don't have an idea why this worked, but it worked. :D

Related

Occasional BeanCreationException in Java Spring Boot project built with Gradle

Sometimes I get a BeanCreationException when starting a Java Spring Boot single-JAR application built by Gradle. My investigations show that it depends on the JAR file and how it has been built by Gradle. Most often (but not always) I see the exception when I build the project on a Linux system. But I have never reproduced the issue with a JAR built on Windows or when running from IntelliJ Idea.
I tried to compare the content of a working JAR with the JAR throwing the exception - all the *.class files (including meta and resources) were binary equal, the only difference was in the order the files were stored in the JAR/ZIP archive. I also tried to unpack the failing JAR on Windows and just repack it into a new JAR file (using 7-zip) - the application started without any exceptions. This weird workaround solved the issue, but it's not something I'd like to do after each build on a linux machine.
The exception suggests to check circular references, so I tried replacing #Autowired properties with #Autowired bean constructors to help me to find the problem but that didn't help. The stacktrace does not mention any of my classes, so I don't know what bean could be responsible for the issue. And because of the fact the issue happens only sometimes and is solvable by repacking the JAR file, I'm not sure there are any circular references anyway.
Could you please help me? Any advice or suggestion is welcomed.
JDK: openjdk 8u262
Gradle version 5.6
Spring boot 2.3.1
Exception message:
BeanCreationException: Error creating bean with name 'webConfig':
Invocation of init method failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource
[org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]:
Unsatisfied dependency expressed through method 'requestMappingHandlerAdapter' parameter 0;
nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException:
Error creating bean with name 'mvcContentNegotiationManager':
Requested bean is currently in creation: Is there an unresolvable circular reference?
By default, Spring manages itself bean's lifecycle and then, arranges their initialization order during the startup.
Here a full example of usage #DependsOn annotation to order the bean instanciation.
You can also found more detail in the official Spring documentation

Eclipse tomcat on web application start java.lang.ClassNotFoundException: org.mockito.Mockito

I can not start web app in eclipse embedded tomcat, but if I deploy war file in standalone tomcat then it works.
The exception I get is:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name defined in class path resource Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Factory method threw exception; nested exception is java.lang.NoClassDefFoundError: org/mockito/Mockito
The file exception is referring to is annotated with #Configuration and is located in src/test/java;
purpose of the file is to create mock beans for test cases.
The fix to the problem is this link:
How to prevent eclipse from deploying test classes on Tomcat?
The cause of the problem was, when eclipse was assembling a war file it would include src/test/java dir in it, and the dependencies were missing for test cases.
because in pom dependencies for test had test which means that maven will not include those jar files in final bucked product meaning war file.

Either application or integration test Spring context creation fails due to properties file location type

Our application should use a .properties file which is created in deploy time on the host filesystem, thus it is not being bundled with the application .war in build time. It is opened and read by a loader class during the Spring application context creation
<bean id="propertiesLoader" class="com....PropertiesLoader">
<property name="propertiesFileLocation" value="${PROPERTIES_FILE_LOCATION}"/>
...
where the file path value of PROPERTIES_FILE_LOCATION is defined in theapplication.properties file in src\main\resources of the application's -web maven module
PROPERTIES_FILE_LOCATION=/home/.../propertyfilename.properties
and the type of the propertiesFileLocation field is String and it is being accessed via new FileInputStream(propertiesFileLocation) in PropertiesLoader.java class
With this setup the application context creation is successful. However, we also have some integration tests in our project which also setup a Spring context for their execution. We though to store a copy of propertyfilename.properties file into src\test\resources of the -it maven module and refer it from its it.properties like
PROPERTIES_FILE_LOCATION=classpath:somedirectory/propertyfilename.properties
however during the creation of the integration test context we receive the following exception
[ERROR] Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'propertiesLoader' defined in URL
[ERROR] Caused by: java.io.FileNotFoundException: classpath:somedirectory\propertyfilename.properties
(The filename, directory name, or volume label syntax is incorrect)
Now if we modify the type of the propertiesFileLocation field to org.springframework.core.io.Resource and we access it via propertiesFileLocation.getInputStream() in PropertiesLoader.java, that makes the integration tests context creation succesful, but at the same the real application context creation fails with
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'propertiesLoader' defined in URL
[file:/.../tomcat/work/Catalina/localhost/_/loader/conf/spring/springmvc/springmvc-util.xml]: Invocation of init method failed;
nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/home/.../propertyfilename.properties]
This seems to be a "deadlock" situation, as either the application or the integration test context creation fails. Is there a way with which both context can be succesfully created?
Resource loading is quite well documenten in the Spring References Guide. When you don’t prefix the resources with the location to load it from it will default to the default location of the ApplicationContext. For the web application that will be the root of the archive, basically what is in the WEB-INF directory. \
You want to load a file resource for this prefix the resource with file: and in your test use classpath: to have it loaded from the `classpath. This way it will work regardless of which default location the application context uses.

WebLogic 10.3.7 File Upload returns "Error creating bean with name 'portletMultipartResolver'"

I am using Spring Portlet mvc with file upload. When I was using WebLogic 10.3.0 it was working fine. I am migrating to WebLogic 10.3.7. Here with the same code I am getting below error:
javax.portlet.PortletException:
org.springframework.beans.factory.BeanCreationException: Error
creating bean with name 'portletMultipartResolver' defined in
PortletContext resource Instantiation of bean failed; nested exception
is org.springframework.beans.BeanInstantiationException: Could not
instantiate bean class
[org.springframework.web.portlet.multipart.CommonsPortletMultipartResolver]:
Constructor threw exception; nested exception is
java.lang.NoClassDefFoundError: javax/portlet/ActionRequest
WebLogic server is not able to find ActionRequest.class. I have tried several options like placing jar file (netuix_common.jar) which contains ActionRequest.class inside the application war file but still it didn't work.
What can I try to resolve this?
java.lang.NoClassDefFoundError - you get this error when weblogic server finds this class in its classloader but not the one with the correct version.
you did the right thing by adding it to the application war file, you may want to add the flag of " prefer-web-inf-classes "
https://docs.oracle.com/cd/E23943_01/web.1111/e13712/weblogic_xml.htm#WBAPP601

Spring Configuration file error

I am trying to run a simple program using a spring configuration file. In the configuration I am creating a bean for the JMS template. When I run it from eclipse everything works perfect but if I try to run it from the command line I get the following error.
Error creatign bean with name JMSTEMPLATE definded in class path resource [config.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/jms/JMSException
Does anyone know why this could be? I've double checked my class path and it is fine.
You are forgetting to include the jms.jar in your classpath.
Are you including JMS jars in your classpath? This error suggests that they are missing at runtime.

Categories