简体   繁体   中英

Spring boot as war vs jar

We are developing a middleware platform with Spring-boot and REST and we are NOT going to fully microservice architecture, but creating small services based on functionality. Eg: catalog-service-api is for CRUD operations on the catalog and online-services-api for IoT.

1. Should I go for war or jar?

I feel the disadvantage of jar here is, each jar creates a new process (new tomcat) which I don't want to scale at this moment.

As we are developing a cloud-based enterprise product, Do we need jar OR war? Microservices NOT required.

2. If I go with war, is spring boot admin will work as expected?

We are facing deploying spring-boot admin in one server and the client is another server.

@SpringBootApplication
@EnableAutoConfiguration
@EnableAdminServer
public class SpringBootAdminServerApplication extends 
SpringBootServletInitializer{

public static void main(String[] args) {
    SpringApplication.run(SpringBootAdminServerApplication.class, args);
}
}

Client:

@SpringBootApplication
public class SpringBootAdminClientApplication extends 
SpringBootServletInitializer{

    public static void main(String[] args) {
        SpringApplication.run(SpringBootAdminClientApplication.class, args);
    }
 }

client application.properties: spring.boot.admin.client.url= http://localhost:8085 spring.boot.admin.client.service-url= http://localhost:8085/spring-boot-admin-server

Admin server is running but client is not available.

Please suggest.

Should I go for war or jar?

That choice solely depends on you. I think if you understand basic difference you will understand that. See below:

A.war file is a Web Application Archive which runs inside an application server while a.jar is Java Application Archive that runs a desktop application on a user's machine.

So, if you want multiple applications running under same application server choose war. Though trend is to have jar files having 0 sever configuration & capable of running anywhere (eg springbooot fat-jar).

If I go with war, is spring boot admin will work as expected? It's your applications and server and other settings of machine, a war or jar type have nothing to do with it.

I suggest that you should go for Spring Boot application with JAR with docker containers.

  • What happens if one of your project leaks memory or CPU, is that mean your tomcat will fail?
  • What happens if you need to restart one of your project?

On the other hand, if your projects are depend on each other you might want to use war.

There is no better approach, it depends on project and your knowledge of devOps for docker. Personally, i run all my projects with Jar for seperate processes with or without docker.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM