Hotswap a Spring bean class deployed on a development server without any restarts

15 Views Asked by At

I have a spring-boot application deployed on an on-prem development server. I already have a solution where I can patch a new version of the class file and the new changes are reflected after an application restart.

I am looking for a solution where I can hot-swap/live-reload a bean without actually restarting the application.

Example: Let's assume the below is the current bean that is already deployed and used in a remote development server.

`
@Data
@Slf4j
@Component
Class Employee {
  int empNo;
  String empName;

  public void printDetails() {
    log.info("EmpNo: {}, EmpName: {}", empNo, empName);
  }
}`

Now I have a new version of the same class with an additional field and method as shown below.

`
@Data
@Slf4j
@Component
Class Employee {
  int empNo;
  int empAge;
  String empName;

  public void printDetails() {
    log.info("EmpNo: {}, EmpAge:{}, EmpName: {}", empNo, empAge, empName);
  }

  public void calculateBonus() {
   log.info ("Calculating Bonus");
  }
}`

I want to patch this change without restarting the application on the remote development server as my changes are very minimal and restarting the entire app is a costly operation for my use-case.

I already explored spring-dev-tools and it doesn't help my use case as the remote live-reloads work every time I make a change in my IDE which isn't what I am looking for.

I also explored Dynamic class loader but couldn't come up with a simple working solution.

0

There are 0 best solutions below