How to run 2 spring boot applications in your local machine - spring-boot

In my windows 10 machine, I want to run 2 spring boot applications one at port 8084 & another at port 8081 which are basically basically 2 versions of the same application so that I can compare the behavior of older version with the newer one. In the application.yml file for the older version, I have defined the serever.port as 8084 & in newer version as 8081.I assume that both of them uses tomcat under the hood. If I were directly using tomcat, I could have made changes in server.xml. But in spring boot I do not have access to underlying tomcat. Now when I start the older version at port 8084 it starts fine. But when I start the newer version at port 8081 it gives bind exception - "Web server failed to start. Port 8084 was already in use". I am running both of them from IntelliJ

Is this two different versions of a codebase? Create two duplicate projects on your local machine by checking out the two versions.
Start two separate instances of IntelliJ, one for each of the two local copies. Edit the port for one of them. Run them in their own IntelliJ instances.
It's clumsy and repetitive, but it'll work.
I assume this is a temporary, one-time exercise that will be unnecessary once the comparison is complete.

Related

Start a spring boot application inside another java application?

I have two java applications:
a server starting with spring boot
a client using it (through REST api)
For the time, I start both applications in differents processes.
How could I start the server from the client to obtain a "standalone" application? The use of ProcessBuilder to call java.exe is a solution, but it has drawbacks: it will be OS dependant and cannot assure the server process will be shutdown / killed as the client leaves.
From the architecture point of view leave them separate is the best option, as you have a server and a client separate, it will be the behavior in a productive environment.
If you need it only during the development phase, and your reason to run both together is to save time, you can build both in containers using Docker. Basically create two applications, building from two different folders, and then you will start both together.
I found a solution in https://www.toptal.com/spring-boot/spring-boot-application-programmatic-launch . Igor Delac
opens the jar file containing the server to find the class ...loader.archive.JarFileArchive (and some other)
instanciates it and uses it to start the application on the jar itself.
The jar file is not extracted nor modified. Only a few classes are read.

Configuring Spring Eureka Client through environmental variables in CF

Trying to get a older version of Spring Boot running on Pivotal Web Services.
It needs to connect to a Eureka server. I have stood up a new Eureka server in the same space the Client App is running on in PWS.
As I don't have the code for the Client application (can't modify the application property/yml files), I need to configure the Client's Eureka client to connect to the new Eureka server using Environmental Variables.
Here is what I have tried:
In the Cloud Foundries 'manifest.yml' I currently have:
---
applications:
- name: <Client application name>
...
other non related settings
...
env:
EUREKA_INSTANCE_HOSTNAME: https://<pws route of eureka server>
This is not picked up.
It looks like that property is picked up like that:
https://jar-download.com/artifacts/org.springframework.cloud/spring-cloud-netflix-eureka-client/1.1.0.RELEASE/source-code/org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration.java
I have tried a few variable names:
eureka.instance.hostname
EUREKA_CLIENT_SERVICEURL_DEFAULTZONE
eureka.client.serviceUrl.defaultZone
I also tried setting a SPRING_APPLICATION_JSON to contain these combinations in the same way in the manifest.yml.
None of them seem to get picked up.
Is there a different way that this can be done? Again, I don't have access to the code, only the Jar.
So its not pretty, but I was able to modify the application.properties files in the Jars using VIM to contain this setting:
eureka.client.serviceUrl.defaultZone=<pws route>/eureka/
Just made the Jar write-able, added that setting, saved and then cf push'd it up. Works. Not sure why the ENV did not work, but its not worth fixing. Everything in this Jar is ancient (Spring Cloud version 1.0). Its all going to get re-written anyway, just need the legacy version running somewhere stable while that work happens.

Is it possible to have 2 different services with the same application name?

Let's say I have a service named "FooService" running in a docker container and a second service named "BarService" running in a second docker container. Both services register with Eureka (running in another docker container). Is it possible to have the same application name for both services? E.g. http://localhost/myservice/foo should call the FooService and http://localhost/myservice/bar should call the BarService. Development environment is Spring Boot and the services are implemented as Spring RestControllers. Just put "spring.application.name=myservice" in both bootstrap.properties files and then put #RequestMapping("${spring.application.name}") in the RestController will not work, of course. But is it somehow possible to register the services with a unique identifier and still call them with a common URL path?
Yes, I think this is a very common use case. You develop version service-a, version 1, and you want to deploy service-a, version 2, (canary or blue/green) You can deploy both versions, and register both versions with Eureka, and traffic will be sent to both versions. After you verify version 2, you can shut down version 1.

apache-commons-dbcp connection pooling - works in dev, not in further environments

I have a Struts2 WebApp using Spring with apache-commons-dbcp. While running in my local development environment, the application opens no more than 8 connections, which is the default value for maxActive.
However, once the WAR is moved to a test server - running the same version of Tomcat (6.0.35) as my development box - the application open far more connections. After a couple minutes I can have around 40 connections open, while the same test in development only results in 8 connections.
This appears to be a configuration issue between the two environments, but I'm not sure what I'm looking for. Any advice?
Turns out that my local instance of Tomcat was setting this Java option:
-XX:+UseConcMarkSweepGC
The test and production servers were not. Enabling it resolved the issue.

Glassfish tuning

We have here an application developed using Java EE 5 stack (using JSF, RichFaces, EJB, JPA, Hibernate, JAAS) that runs inside Glassfish 3.1! The thing is we are in need to run it as an installable deploy (actually many deploys =]).
My question is: What can we do to have the smallest footprint for the system?
I've already studied about:
uninstalling thing through upgrade tool (e.g. the admin parts),
run the application using embedded glassfish (but using the already existent domain),
configuring domain.xml to erase features (but at a trial and error way),
found some work on how to configure glassfish for production environment.
But as the system will be used by one user at a time, I would like to listen from you about options in this environment.

Resources