How to run multi module project in Spring boot - eclipse

My maven project structure:
My question is, I need to run only parent module, that automatically instantiate that's sub modules(tomcat server). Is it possible with spring boot multi module project?
Note : I am using STS.
parent packaging is pom and child module packaging is jar files.
My Parent pom file
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>com.test</groupId>
<artifactId>test-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>test-parent</name>
<description>testproject for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.7.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<modules>
<module>userService</module>
<module>authenticationService</module>
<module>dataLayerService</module>
</modules>
My Question is how can I run parent project using tomcat? If I run parent project, child modules are automatically gets run or not?
Thanks in advance !!!

I have configured all the the microservices inside one docker-compose file. using docker-compose up command all modules gets started.(Make one microservice as service and others are child microservice)

Related

When I generate Spring starter project with eclipse STS tools there is an error occurs in pom.xml first line. But I found no error in pom.xml

I have created a Spring starter project with eclipse STS tool after creating project there is an error in pom.xml first. But I found no error. I have tried Updating project with and with out forcefully but error still persists
Thank you
<?xml version="1.0" encoding="UTF-8"?> <!-- error occurs here -->
<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.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.web-app</groupId>
<artifactId>FirstWebApp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>FirstWebApp</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Project runs but not working.
[This is the image of eclipse workspace] [1]: https://i.stack.imgur.com/a9fGB.png
Well , this is the latest well known problem of Eclipse when working with Spring Boot 2.1.5.
The workaround is to add the following to pom.xml :
<properties>
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
</properties>

Hierarchical dependency issue on Maven Build

This is the error I have when building my Maven Project.
Source of project: Project, Github link
Setup: Eclipse IDE on Windows.
[ERROR] Failed to execute goal on project uicontroller-service: Could not resolve dependencies for project poc.microsvc-angular:uicontroller-service:jar:0.1.0: Failed to collect dependencies at poc.microsvc-angular:microservice-common:jar:0.0.1-SNAPSHOT -> org.apache.kafka:kafka_2.10:jar:0.8.2.1 -> org.apache.zookeeper:zookeeper:jar:3.4.6 -> org.slf4j:slf4j-log4j12:jar:1.7.21: Failed to read artifact descriptor for org.slf4j:slf4j-log4j12:jar:1.7.21: Could not transfer artifact org.slf4j:slf4j-log4j12:pom:1.7.21 from/to public (https://globalrepository.mclocal.int/artifactory/public): connect timed out -> [Help 1]
[ERROR]
Here is my pom.xml file:
<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>poc.microsvc-angular</groupId>
<artifactId>uicontroller-service</artifactId>
<version>0.1.0</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.5.RELEASE</version>
<relativePath />
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<docker.plugin.version>0.3.258</docker.plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-messaging</artifactId>
</dependency>
<dependency>
<groupId>poc.microsvc-angular</groupId>
<artifactId>microservice-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.10</version>
<configuration>
<imageName>microsvc-angular/${project.name}</imageName>
<dockerDirectory>${project.basedir}/src/main/docker</dockerDirectory>
<skipDockerBuild>false</skipDockerBuild>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
Is there a chance of corrupted jars or is it something else?
Looks like your local ~/.m2/settings.xml or C:\Users\myUserName\.m2\settings.xml for windows has configuration to point to a corporate /internal mirror of maven central. You can temporarily remove this potentially to fix your issue.

SpringBootApplication can not be resolved to a type error in Spring tool suite and maven

I have created the maven project in spring tool suite. I created the pom.xml with required dependencies but facing error as "SpringBootApplication can not be resolved to a type".
I have tried a couple of solutions like Maven -> Update Project..., Clean Project, deleted local repository directory of Maven (.m2), etc... also I tried creating another maven project but still the same error.
I think this is eclipse spring tool suite problem with maven.
Is there any solution like patch by eclipse or anything else?
Thanks in advance!
Pom.xml as follows
<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>io.javabrains.springbootquickstart</groupId>
<artifactId>cource.api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Java Brains Cource API</name>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
</parent>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
<type>pom</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<properties>
<java.version>1.8</java.version>
</properties>
</project>
You did not add the correct dependencies.
You should add
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
as a dependency (in <dependencies>) instead of spring-boot-starter-parent.
Parent just defines the versions but does not actually add any dependency (you use it as a <parent> in Maven).
If you have test, also add spring-boot-starter-test.
I would also suggest to use https://start.spring.io/ to generate a working Spring Boot base project (also available from STS in File->new->Other->Spring Starter project).
<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>io.javabrains.springbootquickstart</groupId>
<artifactId>cource.api</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Java Brains Cource API</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.8.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<properties>
<java.version>1.8</java.version>
</properties>
</project>
Copy/Paste it in your POM.xml. Update the Maven project and it will fetch the required JARs.

The type org.springframework.context.ConfigurableApplicationContext cannot be resolved

I am getting the following error, when i tried to create my first application in Spring Tool Suite:
Multiple markers at this line
- The type org.springframework.context.ConfigurableApplicationContext cannot be resolved. It is
indirectly referenced from required .class files
- The method run(Object, String...) from thae type SpringApplication refers to the missing type
ConfigurableApplicationContext
This is the following 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>
<groupId>com.welcome</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>welcome</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
This is the Controller Used
package com.welcome.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
#SpringBootApplication
#EnableAutoConfiguration
public class WelcomeApplication {
public static void main(String[] args)throws Exception {
SpringApplication.run(WelcomeApplication.class, args);
}
}
Can any one help in this? what is my mistake? And it is showing red exclamation mark on the project folder.
Your maven cache is corrupted. To resolve this problem, follow the steps below:
Go to the directory of your project on the command line.
Make sure your POM.xml is in the same directory as your command line
Run the command
mvn dependency:purge-local-repository
If you receive build successful message, means the error has been resolved.
If error is still there, delete your (~/.m2/repository/org/springframework) folder and run
mvn package
It will work properly now.
Updated the spring-boot-starter-parent to latest version . Resolved the problem for me
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
**<version>1.3.6.RELEASE</version> // update this to latest**
<relativePath/> <!-- lookup parent from repository -->
</parent>

How can I specify the spring-data-mongodb version using spring-boot?

I want to use the latest version of spring-data-mongodb, in order to use the full text search feature, but I don't know how I can specify this using the spring-boot-starter-data-mongodb dependence.
You can read here: maven repository that the spring-data-mongodb version is not specify.
This is my pom file:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!-- Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Spring Boot Rest -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<!-- Spring Boot Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- Spring MongoDB integration -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
Spring Boot defines all its dependencies and dependency versions in the spring-boot-dependencies project. This project only contains a pom with only dependencies and versions as properties.
Spring Data releases all of its compatible releases in a so called release train and this makes sure that all dependencies of that version will work together.
When you take a closer look a the pom you will see a maven property named spring-data-releasetrain.version and for the upcoming Spring Boot 1.2 it points to the latest release train version Evans-RELEASE. The 1.1.7 version points to the previous version Dijkstra-SR4. I would suggest an upgrade from 1.1.6 to 1.1.7 just in case.
You're project already has the spring-boot-starter-parent project as its parent so in theory upgrading the Spring Data versions should be as easy as overriding the specified property.
<properties>
<spring-data-releasetrain.version>Evans-RELEASE</spring-data-releasetrain.version>
</properties>
As mentioned earlier the use of the release train is preferred as this will make sure you get all the compatible versions.
You can find that mongodb dependency in the parent project pom file
/../.m2/repository/org/springframework/boot/spring-boot-dependencies/2.3.0.RELEASE/spring-boot-dependencies-2.3.0.RELEASE.pom
That file defines all the dependency version for other libs SpringBoot use
<properties>
<activemq.version>5.15.12</activemq.version>
<antlr2.version>2.7.7</antlr2.version>
...
<mongodb.version>4.0.3</mongodb.version>
...
</properties>
So if you want to use different version for mongodb, define a properties in your pom file to override the default one like (I think this will only work if you use spring-boot-starter-parent as parent )
<properties>
<mongodb.version>3.11.2</mongodb.version>
</properties>
Answer by #sendon1982 worked for me. Here is an example of my POM.XML. I am adding it as an answer here because I could not paste in my pom file as a comment to sendon1982 answer...
<?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 https://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.3.3.RELEASE</version>
<relativePath/>
</parent>
<groupId>test.barry</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>test</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<start-class>test.barry.Main</start-class>
<mongodb.version>4.1.0</mongodb.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<version>2.3.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver-sync</artifactId>
<version>4.1.0</version>
</dependency>
</dependencies>
</project>