Sprint Boot App (Fat JAR) Load external jars - spring-boot

I have spring boot application (fat jar). But i need to load some external jar's(which are not part of the fat jar). The external jar's contains some camel & spring components.
Currently when I try to specify the classpath(directory where the external jars are available), the spring boot #Componentscan isn't picking up those files.(java -cp xx)
How to tell the spring boot application to include the external directory where the jar's are available during #ComponentScan.
Appreciate you support

Related

Can Spring boot based application's embedded jetty/tomcat also run external war file

We are trying to evaluate following scenario (to support couple of legacy apps and new apps).
Team has developed application based on spring boot and working OK (using embedded Jetty ie. typical spring boot JAR)
We have couple of legacy small applications (Spring MVC/Apache Camel based) which were packaged as WAR .
WARs can not be placed into " src/main/resources" (application is already packaged)
We know that in spring boot we can specify external lib directory from where JARs are scanned and initialised.
Is there any way where we can provide WAR file to this spring boot application as runtime argument and it gets exploded-initialised-served (along side of spring boot app)
(This is not duplicate of How to run external war file with embedded tomcat of spring boot with gradle? .. We are having different scenario)

read properties from third party jar in spring boot application

I’m adding a third party jar as a maven dependency in my spring boot application A. Third party jar is a jar of another spring-boot application B. it has its own configurations saved in conf folder "B.properties".
I have used #Import({B.class}) annotation to import the beans of application B in my application but not able to access the configuration properties of application B. Is there any way to access the configuration properties of an application from a jar?
You can create your own Config Server just add #EnableConfigServer annotation and provider configurations from service A to service B.
You can review this example:
https://spring.io/guides/gs/centralized-configuration/
UPDATED Fix adding
#PropertySource("classpath:/conf/B.properties"),

Spring Boot with maven war dependancy

I have Spring Boot web project with dependency to maven overlay war file which is also Spring web project. War is included in pom.xml.
How can I deploy that war along with Spring Boot application so I can use rest endpoints that belong to war file. I'm trying to start application from STS simply by running it as Java application. While application is starting, I can see only URLs that belong to Spring Boot project, but URLs that belong to war file are missing.
I believe Spring boot does not support that. See issue here
Try building a war and deploying it into a container.

Should I use `src/main/webapp` to serve static content with Spring Boot?

The documentation of Spring Boot states:
Do not use the src/main/webapp directory if your application will be
packaged as a jar.
But surprisingly the Spring Boot Sample for static web files is using the /src/main/webapp directory. And also JHipster is using the webapp folder.
So I'm confused. Is the warning in the documentation of Spring Boot outdated? Is it now considered good practice to use src/main/webapp to serve static files with Spring Boot jar applications? And if not, what is the recommended practice now when using Spring Boot in a Maven setup?
From Spring Boot Reference Documentation (emphasis mine):
By default Spring Boot will serve static content from a directory called /static (or /public or /resources or /META-INF/resources) in the classpath or from the root of the ServletContext. It uses the ResourceHttpRequestHandler from Spring MVC so you can modify that behavior by adding your own WebMvcConfigurerAdapter and overriding the addResourceHandlers method.
In some of my (Maven) projects I am currently using src/main/resources/static because it's considered part of the classpath by default and IDEs (like Eclipse) tend to like this.
Be wary because Spring Boot 2.4.x disables the default servlet (which impacts on loading of src\main\webapp and anything else at the root of your WAR file. JAR file packaging is disabled by default but there is a configuration option to all that too - see Spring boot: configure it to find the webapp folder.
https://github.com/spring-projects/spring-boot/issues/22915
The full release notes are here: https://spring.io/blog/2020/11/12/spring-boot-2-4-0-available-now
hi if i understand your question
when your are using jar packaging in spring boot
yo will put your resource in META-INF/resources
and you can use this jar package in other project and call resource ,
you can move webapp to meta-inf directory using maven and gradle build

How to configure wily with spring boot application

I have created an application as spring boot application,Now i want to integrate this application with wily,where i ll passed wily parameter in application to configure application.
The fact that it's a Spring Boot application shouldn't make any difference. If you're using an executable jar file, you'll need to configure the agent when you launch the jar, for example:
java -jar my-app.jar -javaagent:<Agent_Home>/Agent.jar -Dcom.wily.introscope.agentProfile=<Path_To_Agent_Profile>
If you're deploying your Spring Boot application as a war file to a servlet container or application server, you'll need to be make the equivalent configuration changes. The documentation describes how to configure Tomcat.

Resources