how to choose which dependency resources will be used in spring boot application - spring

I have fat-jar spring boot application in jar A.jar
in this fat-jar I have folder lib with two jar files (dependencies)
let's say B.jar and D.jar in each of these jar file (B and D) we have application.properties (resource) which is loaded automatically during initialization of application.
Unfortunately application.propertiesfrom D.jar is loaded before application.properties from B.jar
How to load application.properties from B.jar instead of application.properties from D.jar ?

Depends on location on classpath always first application.properties will be loaded. Order of jar files on classpath in my case (maven pom.xml) depends on order of registering dependencies in pom.xml
If I use
<dependencies>
<dependency>
//B.jar
</dependency>
<dependency>
//D.jar
</dependency>
</dependencies>
then application.properties from B.jar will be loaded.

Related

Adding runtime dependency jars with maven

Is there a way to include runtime dependency jar to maven project. Basically I want to include project1 as dependency jar at runtime to project2.
Project1
src/main/java
com.test.example1
Project2
src/main/java
com.test.example2
lib
I received error - 'dependencies.dependency.systemPath' for com.test.example2.PublishItem:jar must be omitted. This field may only be specified for a dependency with system scope
<dependency>
<groupId>com.test.example2</groupId>
<artifactId>PublishItem</artifactId>
<scope>runtime</scope>
<version>1.0-SNAPSHOT</version>
<systemPath>${project.basedir}/src/main/java/lib/</systemPath>
</dependency>

spring boot project as dependency inside another spring-boot project

I have a spring boot project(project-lib) which I am including as maven dependency in another spring boot project(my-project).
now the project-lib uses logback and i want to exclude the logback dependency in my-project.
Also currently project-lib is defined as dependency with classifier jar-with-dependencies
Is it possible to define project-lib as normal dependency instead of jar-with-dependencies.
I tried to define it as normal dependency assuming it will download all the required dependencies as project-lib/pom.xml has already defined the required dependencies to run project-lib but it did not work that way.
part of pom.xml of my-project
<dependency>
<groupId>com.xyz/groupId>
<artifactId>project-lib</artifactId>
<version>0.0.4-SNAPSHOT</version>
<classifier>jar-with-dependencies</classifier>
</dependency>

Spring boot logging with log4.properties file in not working

I have log4j.properties file under resources folder. Now I am passing logging.file=/Users/jkuriakos/web/rnt/dr/rnt.log in application.properties file.
How can I use the log4j.properties file to load all information (like smtp server etc) from log4j.properties file?
Exclude the spring-boot-starter-logging from your pom file and add following dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j</artifactId>
</dependency>
This should make spring boot pick up log4j.properties from resources folder.
http://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html#howto-configure-log4j-for-logging

Maven/Spring multi module project logging

I am trying to convert a huge maven/spring webapp to a multi module project.
Logging is implemented with this method (http://docs.spring.io/spring/docs/4.0.2.RELEASE/spring-framework-reference/htmlsingle/#overview-logging-slf4j) in the huge project. What is the correct way to do this in a maven multi module project? Is it necessary to define this in every pom.xml or only in my main pom.xml.
My main pom.xml defines this dependency:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>4.0.2.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Is it possibly to exclude commons-logging on this dependency?
Update:
The project structure:
Parent Project:
Project A: jar
Project B: jar
Project C: war
Project D: war
All projects using parts of the Spring framework. I am using SLF4J for logging. What is the correct way for including SLF4J in this project setup with maven?
It should only be necessary to exclude commons-logging from "spring-core", but some third-party libraries also include it, so that isn't always enough. You could try using Spring Boot starters to build up your Spring dependencies (even if you aren't using other Boot features), since the default logging system is logback and commons-logging has been carefully excluded.

How to add all dependency in my project pom file?

I have added around 100 jars in my local Apache Archiva. Now i will want to add all these dependency jar to my project Pom.xml file.
Can it possible to add all these dependency by single Copy-paste? Right now i have to copy each individual dependency from Apache Archiva and paste into my project pom.xml file.I have to copy-paste these lines in my Pom.xml file for each jar which is very tough task.
<dependency>
<groupId>org.csdc</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
It's very unlikely that you need all 100 jars as direct dependencies. In maven, you have to list your direct dependencies - one by one, yes. However, you don't need to list your transitive dependencies because maven will manage that for you. This is one of the most fundamental improvements over older manual classpath management java building.
No All dependency of all jar,
because of in that jars some of the dependency have same group Id ,
so that have fetch all the jars that included.
some of the dependency is writing in pom.xml file
for example code is
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.4.0.GA</version>
</dependency>
the above dependency fetch all jars of related to hibernate-annotation
- hinernate-annotation
- hibernate-common-annotation
- hibernate-core jar files to be fetched.....

Resources