Can Jersey resources classes be instantiated in Spring Boot if they're external? - spring-boot

I'm developing a Spring Boot app using Jersey for Rest.
The app will regularly have Rest controller and supporting classes added to it, basically adding small, specific logic at specific endpoints.
I'd like to be able to drop jars containing Jersey controllers into a directory specified by loader.path and have them created (including Spring auto-wiring) by just restarting the server.
Some Jersey resources form the base of the application and these are working fine because I've registered them via a ResourceConfig class but I'd really like to add resources without requiring a rebuild of the app.
Is this possible? I'm failing to get the resources created, I'm not even sure they're in the classpath.
In application.properites, I added:
-Dloader.path=lib/,resources/
and I've copied the jars into these folders, but they don't get instantiated.
Anybody got any ideas?

Related

Spring boot web app - not able to pick the static content

Spring boot web app with angular bundle was working fine earlier
Then I added a gradle dependency which is a library that is built within my organization to achieve some api calls. And after that the view/angular build is not picking up by spring boot application.
My project structure looks like below
web-app\
src\main\java\
WebApplication.java
\resources\public\index.html
\public\main.5214684651aera5146.js
\public\styles.3asd44654e1asd135fsdf.js
\public\other-angular-build-files
application.properties
I haven't added any view controllers/resource handlers by implementing WebMvcConfigurer. Spring boot was able to pick the index.html file as welcome page and I was able to see the page on http://localhost:8080.
But now it is not working, I have gone though below article and tried with different location of view - public, static, resources, META-INF\resources but nothing workout.
https://spring.io/blog/2013/12/19/serving-static-web-content-with-spring-boot
Can someone help how can I debug this issue or override MVC config so that my spring boot should pick the index.html as the welcome page.
In addition to M. Deinum answer you can try to restrict #ComponentScan only in your app and manually create beans from classes from library

How to introduce custom classloader into Spring Boot Jersey application?

I have a Spring Boot Jersey Application. I want to use a custom class loader with it to allow loading classes and resources from outside of standard web application classpath. (I need it to allow customers to add "plugins" to the application without disturbing original application file structure). Any suggestions how can I do that?

Spring RestTemplate dependency issue in Ear

The organisation I work for has a few standalone services using Spring Boot and RestTemplate to communicate with each other and the main monolith (classical skinny War in Ear).
However, we are running into problems with the classpath when we try to get RestTemplate running inside the Ear, but not inside the War. We don't consider making a rest call to be part of the web application, so we moved that code up to a library which gets packaged in EAR/lib. This moved spring-web (4.1.6.RELEASE) to EAR/lib as well, at which point WebApplicationInitializer code stops working.
Is there are way to get the application still kickstarted with spring-web inside EAR/lib rather than WEB-INF/lib? Or should we resign ourselves to either using RestTemplate exclusively in the War/finding an alternative to RestTemplate?
Never mind, apparently when spring-web isn't deployed in WEB-INF/lib, WebApplicationInitializers don't work. We can work around that.

Deploying a third party war in a Spring Boot embedded container

Pardon if this feels a bit of "necroposting". I looked and found only one similar question with no answers here (Spring-Boot Embedded Wars).
I have a service packaged into a spring boot (1.0) container. This service uses activiti (www.activiti.org) to manage some buisiness processes. I am trying to deploy inside the same spring boot container, the war for activiti-explorer. This war has its own web.inf, spring config, et cetera, so it may conflict with the existing spring config, but nonetheless, I'd like to try to deploy that war as it is.
I haven't found any way to do that, and suspect that spring boot doesn't support the deployment of pre-package wars into the embedded container, isn't it?
Just as a warning, I think I can't put the extracted war into the spring-boot jar as I feel it needs a fully functional web container. If spring-boot doesn't offer this functionality, no big deal, we're going to deploy that war on its own tomcat, but it would be handy if it could be.
Thanks
Update
Just to clear better, I have an already running Spring Application standalone server, with its own embedded Tomcat.
Inside the embedded Tomcat I plugged some #Controllers I developed.
Then I was also able to map a third-party servlet using a ServletRegistrationBean (mapped to /servlet-path).
Now I'd like to do something similar with another war that contains a full fledged web application (it's a vaadin/spring 3.2 application with its own libraries, jsps, static resources ...) and would like to map it to (say) /war-path.
I would like to drop the war in a well known location and deploy it into tomcar with a (say) WarRegistrationBean that would let Tomcat handle all the classloading hurdles (as I mentioned, the war is using spring 3.2 while I'm using 4.0 with spring boot, ...).
I suspect that this last feature is not supported by spring-boot or - possibly - even out of scope for the project itself.
You can manually enhance a war archive by adding the stuff that the boot plugin does (classes from the loader and some META-INF information). Easiest would be to simply enhance an "empty" war, and then merge it with the target one (by exploding them both and re-jarring). The only thing you'd need to add might be a main class.
It's still a gap in the Boot tooling. If you think it needs filling please raise an issue and/or send some code.

Spring: Injecting services from a different project

In the project our team's working on, we currently have 3 separate Spring projects which utilizes the same services. To avoid redunancy and code copy-pasting, we're planning to create a "common" project wherein all the three projects would be dependent on the common project. In this instance, is it possible to inject these services (perhaps using the #Service annotation) to the Controllers of the Spring projects?
EDIT:
I tried implementing this on my own and what I basically did was I configured the pom.xml to get the Spring Context 3.1.1 dependency (which are also being used by my Spring projects) for my "common" project. With that, I was able to annotate my service with #Service. Afterwards, on my Spring project, I set the component-scan to a level wherein my two projects would meet. On my Spring controller, I #Autowired the service from the "common" project. I ran the Spring project and apparently it worked. Is this the best way to do this?
That's absolutely fine, and standard. Spring (unlike CDI) couldn't care less whether your beans come from the current project or from an imported jar.

Resources