Spring Boot & ActiveMQ Artemis: NoClassDefFoundError during start of application - java

When trying to create a Spring Boot Java application with ActiveMQ Artemis I get the following exception:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'artemisConfiguration' defined in class path resource [org/springframework/boot/autoconfigure/jms/artemis/ArtemisEmbeddedServerConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.activemq.artemis.core.config.Configuration]: Factory method 'artemisConfiguration' threw exception; nested exception is java.lang.NoClassDefFoundError: org/apache/activemq/artemis/api/core/QueueConfiguration
From the above exception I have difficult to understand what config might be missing or is it something else? I am using Spring Boot 2.7.3.
It is implemented to the letter as described in the this guide (native and embedded).

The fundamental problem is this:
java.lang.NoClassDefFoundError: org/apache/activemq/artemis/api/core/QueueConfiguration
This means that the JVM can't find this class. This class is in the artemis-commons module. You need to put this on your application's classpath.

Related

Failed to look up JNDI DataSource

This problem may seems redundant but I can't find a suitable solution for my specific problem.
So, I have been using basic JDBC template to make connection to the DB tables in my spring boot application. I have few more features to add and I wanted to follow JPA route. I added spring.datasource.jndi-name and spring.jpa.database-platform to the application.properties file correctly(same as once that are working in my other applications).
Although I'm able to run the current application(with both JPA and JDBC connection) locally, I'm getting following error while building it on weblogic remote server.
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/JndiDataSourceAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.jdbc.datasource.lookup.DataSourceLookupFailureException: Failed to look up JNDI DataSource with name 'jdbc.myDataSource'; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
Can anyone help me with this ?

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 boot cannot create datasource bean from cucumber test context

When running tests in a spring boot based application, spring is unable to create the datasource bean:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath.
Reading this error it is clear to me, I think, that spring did not read my application.properties file located at:
src/test/resources/application.properties
For clairity, I do not want to make use of an in memory database when running my integration tests, for application specific reasons.
This file contains:
spring.datasource.url=jdbc:mysql://127.0.2.1:3306/project-test
spring.datasource.username=foo
spring.datasource.password=bar
spring.datasource.driverClassName=org.mariadb.jdbc.Driver
While when starting the application using bootRun at does read out
src/main/resources/application.properties
and does create the datasource correctly.
My tests are based on cucumber and started using the following class:
#RunWith(Cucumber.class)
public class AcceptanceTests {
}
The test context is started using the following annotations on a BaseSteps class which each class defining cucumber tests inherits from
#WebAppConfiguration
#ContextConfiguration(classes = App.class)
The spring context is started successfuly but it was unable to find my application.properties file and/or use it.
I found the solution.
I added changed the ContextConfiguration like so:
#ContextConfiguration(classes = App.class, loader = SpringApplicationContextLoader.class)
Use #SpringApplicationConfiguration instead of ContextConfiguration. This is needed for Spring-boot application tests.

No suitable default RequestUpgradeStrategy found

I'm trying to run Websocket on Spring (Not STOMP but regular websocket) as seen here. However, after following the tutorial, I get the following exception:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.socket.server.support.DefaultHandshakeHandler#0': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.web.socket.server.support.DefaultHandshakeHandler]: Constructor threw exception; nested exception is java.lang.IllegalStateException: No suitable default RequestUpgradeStrategy found
I got this on several versions of Tomcat, the newest (which I assume really should have JSR 356 support) was a Tomcat 7.0.50
What could I be doing wrong?
I was able to resolve this by simply updating to Tomcat 7.0.52.
You need tomcat websocket if you use jetty
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-websocket</artifactId>
<version>8.0.28</version>
</dependency>

Tomcat work directory empty

My Spring project was successfully deployed on another Linux server. But when I tried deploying it on this Linux server, it won't deploy. When I go to the homepage, I get the error "HTTP Status 404 - The requested resource is not available".
I compared the Tomcat directory of both servers and see only differences in the "work" directory. On this server (the one having problem), under "work\Catalina\localhost\MyProject" directory of Tomcat, I see that it's empty. Turns out that the files got put under "work\Catalina\localhost\_" instead. What's causing Tomcat to do this?
In my tomcat log file, I'm getting this:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'SampleService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.wdc.hydra.dao.DatatypeDAO com.wdc.hydra.service.DatatypeServiceImpl.datatypeDAO; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'SampleDAO': Injection of persistence dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'Sample' defined in class path resource [Sample-dao-context.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;
Does anyone know why this is happening? Thanks.
How does the Spring Container defined? whether its by XmlWebApplicationContext / FileSystemXmlApplicationContext / ClasspathXmlApplicationContext and if its through FileSystemXmlApplicationContext then your directory structure in both the linux servers should be same. like wise others too.

Categories