[JAVA] Launch (old) Spring Boot project in IntelliJ

Nowadays, it is outdated to develop Spring Boot with Eclipse or STS, so let's make it possible to develop with IntelliJ.

If you start without thinking

logBack.xml does not exist

Logging system failed to initialize using configuration from 'classpath:logback.xml'
java.io.FileNotFoundException: class path resource [logback.xml] cannot be resolved to URL because it does not exist
	at org.springframework.util.ResourceUtils.getURL(ResourceUtils.java:135)
	at org.springframework.boot.logging.LoggingApplicationListener.initializeSystem(LoggingApplicationListener.java:307)
	at org.springframework.boot.logging.LoggingApplicationListener.initialize(LoggingApplicationListener.java:276)
	at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEnvironmentPreparedEvent(LoggingApplicationListener.java:239)
	at org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:212)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:122)
	at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:73)
	at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
	at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:336)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)

It was down because there was no logback.xml that should be in the resources folder. In the PJ I was in charge of, it was configured separately for each environment in pom.xml. Re-specify the resource to read and resolve.

ApplicationEventMulticaster not initialized error

2019-04-03 12:42:43.920  INFO 14712 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@4c402120: startup date [Wed Apr 03 12:42:43 JST 2019]; root of context hierarchy
2019-04-03 12:42:44.490  WARN 14712 --- [           main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [jp.yoshiki-0428.app.App]; nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.boot.web.support.SpringBootServletInitializer
2019-04-03 12:42:44.490 ERROR 14712 --- [           main] o.s.b.f.s.DefaultListableBeanFactory     : Destroy method on bean with name 'org.springframework.boot.autoconfigure.internalCachingMetadataReaderFactory' threw an exception

java.lang.IllegalStateException: ApplicationEventMulticaster not initialized - call 'refresh' before multicasting events via the context: org.springframework.context.annotation.AnnotationConfigApplicationContext@4c402120: startup date [Wed Apr 03 12:42:43 JST 2019]; root of context hierarchy
	at org.springframework.context.support.AbstractApplicationContext.getApplicationEventMulticaster(AbstractApplicationContext.java:404)
	at org.springframework.context.support.ApplicationListenerDetector.postProcessBeforeDestruction(ApplicationListenerDetector.java:97)
	at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:253)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:578)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:554)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:961)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:523)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:968)
	at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1033)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:555)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)
	at jp.yoshiki-0428.app.App.main(App.java:17)

2019-04-03 12:42:44.506 ERROR 14712 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [jp.yoshiki-0428.app.App]; nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.boot.web.support.SpringBootServletInitializer
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:181)
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:308)
	at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:228)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:270)
	at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:93)
	at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:686)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:524)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151)
	at jp.yoshiki-0428.app.App.main(App.java:17)
Caused by: java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.boot.web.support.SpringBootServletInitializer
	at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:163)
	at org.springframework.context.annotation.ConfigurationClassParser.retrieveBeanMethodMetadata(ConfigurationClassParser.java:380)
	at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:314)
	at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245)
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:198)
	at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:167)
	... 12 common frames omitted
Caused by: java.lang.NoClassDefFoundError: javax/servlet/ServletContext
	at java.lang.Class.getDeclaredMethods0(Native Method)
	at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
	at java.lang.Class.getDeclaredMethods(Class.java:1975)
	at org.springframework.core.type.StandardAnnotationMetadata.getAnnotatedMethods(StandardAnnotationMetadata.java:152)
	... 17 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContext
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 21 common frames omitted


Process finished with exit code 1

This error took me hours. After investigating, is it an existing bug in IntelliJ? It seems. The solution is to remove the scope tag from spring-boot-starter-tomcat and it will work. (There may be other causes)

pom.xml


<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-tomcat</artifactId>
  <scope>provided</scope>
</dependency>
↓ Delete the scope tag
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>

Reference: https://intellij-support.jetbrains.com/hc/en-us/community/posts/206670989-Spring-Boot-app-shuts-down-automatically

Recommended Posts

Launch (old) Spring Boot project in IntelliJ
Create Java Spring Boot project in IntelliJ
How to create a Spring Boot project in IntelliJ
Run a Spring Boot project in VS Code
Java tips-Create a Spring Boot project in Gradle
View the Gradle task in the Spring Boot project
Create a Spring Boot project in intellij and exit immediately after launching
Set context-param in Spring Boot
Spring Boot 2 multi-project in Gradle
Try gRPC in Spring Boot & Spring Cloud project (Mac OS)
Major changes in Spring Boot 1.5
NoHttpResponseException in Spring Boot + WireMock
Until you create a Spring Boot project in Intellij and push it to Github
Spring Boot application development in Eclipse
Write test code in Spring Boot
Spring Boot: Restful API sample project
(Intellij) Hello World with Spring Boot
Implement REST API in Spring Boot
What is @Autowired in Spring boot?
Implement Spring Boot application in Gradle
Setting project environment variables in intelliJ
Thymeleaf usage notes in Spring Boot
Build Spring Boot + Docker image in Gradle
Static file access priority in Spring boot
Output Spring Boot log in json format
Local file download memorandum in Spring Boot
Loosen Thymeleaf syntax checking in Spring Boot
[Practice! ] Display Hello World in Spring Boot
Launch Nginx + Spring Boot application with docker-compose
Use DynamoDB query method in Spring Boot
DI SessionScope Bean in Spring Boot 2 Filter
(IntelliJ + gradle) Hello World with Spring Boot
Change session timeout time in Spring Boot
A story about a Spring Boot project written in Java that supports Kotlin
SameSite cookie in Spring Boot (Spring Web MVC + Tomcat)
Output request and response log in Spring Boot
Put multiple Main classes in one Spring Project
Create a Spring Boot application using IntelliJ IDEA
Challenge Spring Boot
Use Servlet filter in Spring Boot [Spring Boot 1.x, 2.x compatible]
How to add a classpath in Spring Boot
Build Spring Boot project by environment with Gradle
Spring Boot Form
How to bind to property file in Spring Boot
Spring Boot Memorandum
gae + spring boot
Annotations used in Spring Boot task management tool
Specify the encoding of static resources in Spring Boot
Include external jar in package with Spring boot2 + Maven3
I checked asynchronous execution of queries in Spring Boot 1.5.9
RESTful API multi-module sample in IntelliJ + Jersey + Spring Framework
[Spring Boot] How to create a project (for beginners)
SSO with GitHub OAuth in Spring Boot 1.5.x environment
Add an external jar file in your IntelliJ project.
How to use CommandLineRunner in Spring Batch of Spring Boot
Test field-injected class in Spring boot test without using Spring container
Until you start development with Spring Boot in eclipse 1
Introduce swagger-ui to REST API implemented in Spring Boot
Deploy the Spring Boot project to Tomcat on XAMPP
Until you start development with Spring Boot in eclipse 2
Specify spring.profiles.active via context-param of web.xml in Spring Boot