Maven configuration with Spring Boot & multi modules - run application in Intellij - java

I'm currently working on a REST API with Spring Boot.
I'm new to Maven and have just started coding with IDEA (don't know well this IDE yet), and I have a problem...
Here is my project structure :
parent
pom.xml
main module
controller
domain
App.java (Spring Boot main class)
pom.xml
sub module (need main module as dependency)
controllers
domain
pom.xml
So when I run the project in Intellij, it starts, and I can access all URLs defined in the main module controller. But not the ones in the sub module controller... It looks like only the main module was loaded.
Here is my parent pom.xml :
<project>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.1.RELEASE</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<name>Test :: Test :: Parent POM</name>
<groupId>test.test.test</groupId>
<artifactId>project-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<!-- Specify Java Compiler Version -->
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<!-- Spring -->
<spring-boot.version>1.2.1.RELEASE</spring-boot.version>
<!-- Sonar -->
<sonar-maven-plugin.version>2.5</sonar-maven-plugin.version>
<sonar.language>java</sonar.language>
<sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>
<!-- Plugin -->
<maven-surefire-plugin.version>2.18.1</maven-surefire-plugin.version>
<jacoco-maven-plugin.version>0.7.3.201502191951</jacoco-maven-plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<modules>
<module>submodule</module>
<module>main</module>
</modules>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<includes>
<include>**/*Test.java</include>
<include>**/*IT.java</include>
<include>**/*Story.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco-maven-plugin.version}</version>
<configuration>
<destFile>${project.basedir}/../target/jacoco.exec</destFile>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>${sonar-maven-plugin.version}</version>
</plugin>
</plugins>
</build>
</project>
Here my main module pom.xml :
<project>
<parent>
<artifactId>project-parent</artifactId>
<groupId>test.test.test</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>main</artifactId>
<name>Test :: Test :: Main</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<commons-lang3.version>3.3.2</commons-lang3.version>
<commons-codec.version>1.10</commons-codec.version>
<jsr305.version>3.0.0</jsr305.version>
<!-- Testing dependencies -->
<http-commons.version>4.3.6</http-commons.version>
<jbehave.version>3.9.5</jbehave.version>
<assertj.version>1.7.1</assertj.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>${jsr305.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>${commons-lang3.version}</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>${commons-codec.version}</version>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901-1.jdbc4</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>${http-commons.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>fluent-hc</artifactId>
<version>${http-commons.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
</dependency>
<dependency>
<groupId>org.jbehave</groupId>
<artifactId>jbehave-spring</artifactId>
<version>${jbehave.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
</dependency>
</dependencies>
<!-- Package as an executable jar -->
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
And here the sub module pom.xml :
<project>
<parent>
<artifactId>project-parent</artifactId>
<groupId>test.test.test</groupId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>submodule</artifactId>
<name>Test :: Test :: Submodule</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<commons-lang3.version>3.3.2</commons-lang3.version>
<commons-codec.version>1.10</commons-codec.version>
<jsr305.version>3.0.0</jsr305.version>
<!-- Testing dependencies -->
<http-commons.version>4.3.6</http-commons.version>
<jbehave.version>3.9.5</jbehave.version>
<assertj.version>1.7.1</assertj.version>
</properties>
<dependencies>
<dependency>
<groupId>test.test.test</groupId>
<artifactId>main</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
I think that's correct, but not sure...
I run the project in Intellij with Maven with config :
working directory is root (not sub-module)
command line mvn spring-boot:run -Drun.arguments=--spring.profiles.active=dev -e -pl main
property start-class with parent.main.App
Need your help to configure all that stuff to run Spring Boot with all sub-modules loaded in the IDE for dev purpose... because I readlly don't know what is wrong in my config !
Thx !

You need to tell SpringBoot where to look for your controllers. Per default that only happens in sub-packages of your #SpringBootApplication class (which will probably not include your sub module).
In order to change that you can use #ComponentScan("path.to.package") to change the default package.
Additionally, you can use #EntityScan to do the same for #Entity classes that might be in your sub-module.

Your project structured as:
parent
pom.xml
main module
controller
domain
App.java (Spring Boot main class)
pom.xml (add sub moudle to main module as dependency)
sub module
controllers
domain
pom.xm
if your App.java in a package: com.xxxx.pro,then set the sub module's package is com.xxx.pro,such as your sub module's controller is TestController.java, and the code is:
package com.xx.pro.web;
#RestController
public class TestController{
}
so, this sub moudle's TestController will be sanned by App.java.Try it on, good luck.

also note that in case of JPA Entities and repositories are not in sub packages of Application.java's package then #Entityscan and #EnableJpaRepositories MUST be declared in the Application class, e.g:
#Configuration
#ComponentScan(basePackages="com.my.pack")
#EnableAutoConfiguration
#EnableJpaRepositories(basePackages="com.my.pack")
#EntityScan(basePackages="com.my.pack")
public class Application{
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

Related

Problem with dependencyManagement and dependency versions

I have problem with relations of pom, with dependency versions etc. Below my structure:
My MAIN pom, which gives me the order to build of all projects
<groupId>com.xyz</groupId>
<artifactId>yxz</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>xyz</name>
<modules>
<module>commons</module>
<module>projectA</module>
<module>ProjectB</module>
...
<module>ProjectX</module>
</modules>
COMMONS pom, it is designed to have common dependencies and properties, without any parent
<groupId>com.xyz</groupId>
<artifactId>commons</artifactId>
<version>1.0-SNAPSHOT</version>
<name>commons</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.version>3.8.1</maven.compiler.version>
<java.version>11</java.version>
<lombok.version>1.18.24</lombok.version>
</properties>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
ProjectA pom, include commons dependency, with spring-boot in parent,
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.xyz</groupId>
<artifactId>projectA</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>projectA</name>
<properties>
<java.version>11</java.version>
<spring-cloud.version>2021.0.0</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>com.xyz</groupId>
<artifactId>commons</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
...
<dependency>
some dependencies from org.springframework.cloud
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
...
</build>
ProjectB pom, include commons dependency, with custom framework in parent,
<parent>
<groupId>com.customframework</groupId>
<artifactId>custom.framework</artifactId>
<version>1.8.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.xyz</groupId>
<artifactId>projectB</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>projectB</name>
<properties>
<java.version>11</java.version>
<customeframework.feign.version>10.12</customeframework.feign.version>
</properties>
<dependencies>
<dependency>
<groupId>com.xyz</groupId>
<artifactId>commons</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
...
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-core</artifactId>
<version>11.8</version>
</dependency>
other feign dependecies with 11.8 version
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.customframework</groupId>
<artifactId>custom.framework.feign</artifactId>
<version>${customeframework.feign.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
...
</build>
When i build my all projects then:
projectA has lombok with version from springframework.cloud dependency management, not with version from commons
ProjectB has similar problem with feign, if i add feign dependency with version 11.8, maven use version from customframework (version 9.x)
What i want to do:
I tried add bom pom file, like next module to MAIN pom but how should i add it when i have other dependency management from springframework.cloud
i have 5-6 projects with spring boot parent, some with quarqus and with custom framework and i want configure all dependency versions and parent spring boot versions in one file
If you want to have the same dependencies in all modules then how about you define <dependencyManagement> with all required BOMs and versions in one place (e.g. in commons module)?
It won't bother the modules if they don't include some of the dependencies but it will make sure that all the modules have the same dependencyManagement rules.

How to add spring boot actuator to WAR project

I have spring mvc application. I tried to convert it to spring boot by doing following steps.
Adding spring-boot-starter-parent parent pom
Adding relevant spring-boot-starter dependncy
Removing spring-mvc and other dependency.
Removed AbstractAnnotationConfigDispatcherServletInitializer class.
Added #ComponentScan, #EnableAutoConfiguration to root config class.
This was successful and I could see that application was working but when I added spring-boot-starter-actuator dependency and run mvn jetty:run . http://localhost:8080//actuator returns 404 response.
Can someone please tell me how I can add actuator in this case ?
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.javaguides.springmvc</groupId>
<artifactId>springmvc-java-config-example</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>springmvc-java-config-example Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.13.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<!-- Hibernate Core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.17.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.47</version>
</dependency>
<!-- Hibernate Validator -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.4.1.Final</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.8.v20171121</version>
<configuration>
<webApp>
<contextPath>/sampleno</contextPath>
</webApp>
</configuration>
</plugin>
</plugins>
</build>
</project>
your url is not correct.please check this url: [http://localhost:8080/actuator][1]

Package Not Found Maven Compile Error on Mvn Clean Install

I have a micro-service based application that I am building out locally. I have a situation where micro-service A is depending on micro-service B and as such I have included B in A's pom as a dependency and there are no errors in the code and all of the classes are recognized. However, when I go to do a 'mvn clean install' command on A, I get the error where none of the packages in B are recognized as well as 'Cannot find symbol' for all of the classes from B that I am trying to use in A.
I have tried changing the execution goal of the maven plugin to 'repackage' in the pom of B like:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I have also confirmed that the JAR file is getting correctly built out to my local maven repository in my .m2 folder and made sure that the classes and code is contained there.
I also have tried breaking down the maven commands into sub-commands instead of just doing a maven clean install
POM for MS A
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.oz</groupId>
<artifactId>franchise-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>oz-franchise-api</name>
<description>API for FRP</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- SPRING WEB -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- DATABASE/JPA BACKEND -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- USEFUL TOOLS -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<!-- OTHER OZ DEPENDENCIES -->
<dependency>
<groupId>com.oz</groupId>
<artifactId>core-library</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
POM for MS B
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.oz</groupId>
<artifactId>core-library</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>oz-core-library</name>
<description>The core library for oz</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<!-- SPRING BOOT -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!-- DATABASE/JPA BACKEND -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- MYSQL DATABASE -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.15</version>
</dependency>
<!-- JAVAX VALIDATION -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<!-- LOMBOK -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
If your two microservices both need a set of classes, put that classes into a separate (third) jar, build it as normal jar and use it as dependency in both.

spring boot main class, how to specify

I am working on a project using spring-boot. I have my own parent .pom file, so I can't use the spring-boot parent pom. When I package the project, the main class is not being included in the MANIFEST.MF, even though I specify it in the plug-in configuration. So when I try to run the jar, java says it can't find the main class.
no main manifest attribute, in processor-interface-1.0.0.jar
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>tld.domain.system</groupId>
<artifactId>processor-interface</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<parent>
<groupId>tld.domain.maven</groupId>
<artifactId>super-pom</artifactId>
<version>[0.1,1.0)</version>
</parent>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<log4j.version>2.9.1</log4j.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.5.6.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.oracle.jdbc</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.0.2</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.6.RELEASE</version>
<configuration>
<mainClass>tld.domain.system.boot.ProcessorInterface</mainClass>
</configuration>
</plugin>
</plugins>
</build>
I have drilled into the MANIFEST.MF in the .jar file and there is indeed no main-class: line. How do I specify the main class in the pom so that it is included in the MANIFEST.MF?
I have similar setup and the only difference with you is that my spring-boot-maven-plugin execution is tied to repackage phase:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>my main class</mainClass>
</configuration>
</plugin>
This was not enough approach for us to achieve above requirement...(As somehow spring-boot-maven-plugin was not working in our case).
However I had to complete my mvn command by appending spring-boot:repackage and
<properties>
<start-class>fully qualified name of the main class</start-class>
</properties>

Application startup failed - Failed to process import candidates for configuration class

I'm receiving this error in the stack trace when I try to run:
java -jar spring-boot-starter-web.jar
From my command line on my build for my jar of my Spring Boot application. I'm not sure what is causing this error. I let IntelliJ do the build of the project.
[main] ERROR org.springframework.boot.SpringApplication - Application
startup failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed
to process import candidates for configuration class
[app.ContactRunner]; nested exception is
java.lang.IllegalArgumentException: No auto configuration classes
found in META-INF/spring.factories. If you are using a custom
packaging, make sure that file is correct.
For reference, the ContactRunner class is just:
#SpringBootApplication
public class ContactRunner {
public static void main(String[] args) throws Exception {
SpringApplication.run(ContactRunner.class, args);
}
}
The spring-boot-starter-parent is in the pom.xml as well as the one for the spring-boot-maven-plugin as other people with similar questions have resolved their issue with it. I can't figure out what's happening. Here is my full pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<!-- Output to jar format -->
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starters</artifactId>
<version>1.5.7.RELEASE</version>
</parent>
<artifactId>NameProject</artifactId>
<name>Spring Boot Web Starter</name>
<description>Starter for building web, including RESTful, applications using Spring
MVC. Uses Tomcat as the default embedded container
</description>
<url>http://projects.spring.io/spring-boot/</url>
<organization>
<name>Pivotal Software, Inc.</name>
<url>http://www.spring.io</url>
</organization>
<properties>
<main.basedir>${basedir}/../..</main.basedir>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.3.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<!-- JPA Data (for using Repositories, Entities, Hibernate, etc...) -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- Use MySQL Connector-J -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.5.7.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.194</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<classifier>spring-boot</classifier>
<mainClass>
app.ContactRunner
</mainClass>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
</testResources>
</build>
<repositories>
<repository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-releases</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
</project>
I also tried to build the project with mvn clean package but it fails because of duplicate dependencies that I can't seem to remove, as you may see my issues in this questions, so this was trying another route.
Any ideas? The application runs fine in IntelliJ, but won't with a jar.
I think you should use spring-boot-starter-parent in parent tag. And should remove whole dependencyManagement block.

Categories