Application Running via Spring Boot Run but not via IntelliJ Idea - spring-boot

I am facing the issue where when I am running my spring boot application via Command line
mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Dspring.profiles.active=dev -Dserver.port=8083"
This works fine, but running as Application in intellij I am getting below errors -
Application run failed,
exc.stack=org.springframework.context.ApplicationContextException:
Unable to start web server; nested exception is org.springframework.context.ApplicationContextException:
Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean.\n\tat org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:155)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:742)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:389)\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:311)
What can be the possible reasons, and where should I look into configurations fixes?
There are other questions on this pattern, but none of them have mentioned the error -
Spring Boot application runs fine via Maven but not via IDE Intellij IDEA
ApplicationContextException: Unable to start ServletWebServerApplicationContext due to missing ServletWebServerFactory bean
(For missing servlet bean, but if this is the case, then app should not have started via command line too)
So, I could not find any answer there.

This error could occur when you have Tomcat's dependency scope as "provided", but while running the application, you are not choosing the option "Include dependencies with provided scope".
You could select that option under the Run Configuration for your app.
In some older versions of IntelliJ, you might see a checkbox to enable the same.

Related

gradle error java.lang.NoClassDefFoundError: org/gradle/api/specs/Spec when trying to run unit-tests

I have a gradle based spring boot project. When I would like to run the tests an error message like this appears:
gradle-resources-test:my-project.my-module.test: java.lang.NoClassDefFoundError: org/gradle/api/specs/Spec
What can I do to find out more about the problem?

Trouble deploying Grails 5.1.1 app on tomcat

I have created a Grails 5.1.1 app from the command line with "grails create-app".
It runs fine, from the command line "grails run-app", and I can build a war file which can be run from the command line with "java -jar app-0.1.war".
I then attempted to follow the instructions for deploying in a container (Tomcat 8 and Tomcat 9 in my case) by adding the context-path and changing the build dependency. The documentation says to change "org.springframework.boot:spring-boot-starter-tomcat" to provided in build.gradle. "provided" is not a valid option as far as I can tell. I've tried both providedCompile and providedRuntime with the same result as below.
When I deploy the resulting app-0.1-plain.war I get one of two errors:
The bean 'characterEncodingFilter' could not be registered. A bean with that name has already been defined in class path resource [org/springframework/boot/autoconfigure/web/servl
et/HttpEncodingAutoConfiguration.class] and overriding is disabled.
with the suggested remedy of adding: spring.main.allow-bean-definition-overriding=true
results in a circular bean reference for hibernateDatastore.
Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'hibernateDatastore': Requested bean is currently in creation: Is there an unresolvable circular reference?
I'm using openjdk version "1.8.0_292" of Java, Gradle 7.2 and I tried deploying on apache-tomcat-8.5.73 and apache-tomcat-9.0.56.
Any ideas about what might be wrong with my set up that prevents the deploy war from running?
Edit: This seems to be a manifestation:
https://github.com/grails/grails-core/issues/12288 and/or
https://github.com/grails/grails-core/issues/12278
Though the work around suggested did not work for me I do not experience the same problem with 5.0.3 as suggested in 12278.

Tomcat not starting after changing packaging from jar to war

Firstly, after changing the packaging from jar to war for spring boot application, I am not able to do maven build. Getting below error:
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.goel.GameApplication]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/application.properties]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:189)
at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:331)
The above error comes when maven tries to run app tests. So I commented out the test and ran maven build and I was able to get a war file.
But after deploying the same war file in tomcat(aws), I am getting the same error.
I have followed the 3 step approach properly.Ref: https://www.javadream.in/convert-jar-to-war-in-spring-boot/
I have checked that the build-path does not exclude resource or application.properties
I have tried moving from spring IDE to Eclipse IDE.
I have opened the war file and have verified that the application.properties file is present under WEB-INF/classes/application.properties.
I have read and tried many other things but nothing helped. Any pointers will be helpful. Thanks in advance.
Please do let me know if more info is required,
Java Version: 1.8 ,
Maven Version: 3.6.3 ,
spring-boot-starter-parent: 2.5.4
Exploded war file
Screenshot for SSGApplication

IncompatibleClassChangeError - Uprade to Spring 4.1.7

We have a tomcat application that has a spring container running on 3.0.0. Upgraded to spring 4.1.7, and modified certain classes appropriately. One of the beans that we modified used CronTriggerBean. That was changed to use CronTriggerFactoryBean, and also upgraded to org.quartz-scheduler to 2.2.1. When deploying and starting tomcat, encountered the following exception.
org.springframework.beans.factory.BeanCreationException: Error creating bean
with name 'appsecScheduler' defined in class path resource [application-
context.xml]: Initialization of bean failed; nested exception is
java.lang.IncompatibleClassChangeError: Implementing class at
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean
(AbstractAutowireCapableBeanFactory.java:547)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean
Attached a debugger and found the offending class to be CronTriggerFactoryBean. But this issue happens only when deploying in a Windows environment. WHen the same war is deployed in Ubuntu, the application starts without any errors. For the record, I did a dependency:tree, dependency:build-classpath and ensured that 3.0.0 spring was not in use. The CronTriggerFactoryBean is part of spring-context-support.
Any suggestions on how to debug further or determine which jar is being used?

CDI Beans module deployment failed: couldn't start owb context

I have a Maven project. The build runs properly including tests. But when I run the tests only using Eclipse Luna, then the tests fail:
javax.enterprise.event.ObserverException: Caught Exception while handling event object with type : org.apache.webbeans.portable.events.discovery.AfterBeanDiscoveryImpl
...
Caused by: java.lang.AbstractMethodError: org.apache.webbeans.container.InjectableBeanManager.getInjectionTargetFactory(Ljavax/enterprise/inject/spi/AnnotatedType;)Ljavax/enterprise/inject/spi/InjectionTargetFactory;
at com.sun.faces.util.cdi11.CDIUtilImpl.createHelperBean(CDIUtilImpl.java:76)
at com.sun.faces.flow.FlowCDIExtension.afterBeanDiscovery(FlowCDIExtension.java:120)
... 60 more
INFO - Undeploying app: .../classpath.ear
org.apache.openejb.OpenEJBException: Creating application failed: /home/schnikow/projects/barbuchon2/BarbuchonKernel-2.0r0b-SNAPSHOT/classpath.ear: couldn't start owb context
(full stack trace is too long, I can provide it if needed)
I've add the needed JVM argument (-javaagent:/usr/devel/apache-tomee-webprofile-1.7.1/lib/openejb-javaagent.jar) in the launch configuration. I may miss something trivial, but I haven't any idea, what.
I use Eclipse Luna and Tomee embedded EJB container running on Java 8 virtual machine.
it seems you use mojarra, is it a CDI 1.0 compatible version or 1.1 (only TomEE 2 will be CDI 1.1/1.2 compatible)

Resources