Issue
I have a spring boot project where I have the structure like this:
Project:
- src
- - module 1
- - module 2
- - - Main.class
- - - Bean.class
- pom.xml
I successfully can run it from IntelliJ Idea. But I wanted to test it with Maven wrapper. At first it didn't want to find a main class, I solved this problem with adding source directory:
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>module2.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
But now it doesn't want to create beans even tho from Idea it runs perfectly. What can be the problem? Error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'bean' defined in file [\target\classes\module2\Bean.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to ins
tantiate [module2.Bean.class]: Constructor threw exception; nested exception is java.lang.NullPointerException: inStream parameter is null
Bean is RestController. I'm running it like this:
mvnw clean spring-boot:run
Solution
The project needs to respect the structure src/main/java/{packages}
.
In your case it'll be:
- src
- main
- java
- module 1
- module 2
- Main.class
- Bean.class
- pom.xml
And use this plugin configuration:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Answered By - delephin