spring cloud 打包为war包
程序员文章站
2022-04-26 10:32:18
...
<packaging>war</packaging>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
将tomcat配置文件的端口号改成和微服务端口号一致,微服务打成的jar包改为ROOT.jar
启动文件修改:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@EnableEurekaClient
@EnableDiscoveryClient
@EnableCircuitBreaker
@EnableFeignClients
@ComponentScan("xxx.xxx.**")
public class Application extends SpringBootServletInitializer implements CommandLineRunner{
private Logger logger = LoggerFactory.getLogger(Application.class);
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
public void run(String... args) throws Exception {
logger.info("启动完成!");
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(Application.class);
}
}
@Configuration
public class WebConfiguration extends WebMvcConfigurerAdapter {
@Bean
public MessageSource messageSource() {
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename("static/message/messages");
messageSource.setDefaultEncoding("UTF-8");
return messageSource;
}
}
推荐阅读
-
基于Java的打包jar、war、ear包的作用与区别详解
-
Spring Boot+maven打war包的方法
-
Spring-cloud 服务发现与消费(以ribbon为例)
-
Spring Boot打war包的实例教程
-
详解Linux中将应用程序打包为Snap软件包格式的方法
-
Spring-boot构建多模块依赖工程时,maven打包异常:程序包xxx不存在
-
Springboot打包成jar包和war包,并且可以在外部tomcat下运行访问到
-
JAVA 超详细 将文件夹保留目录打包为 ZIP 压缩包并下载
-
不重新打包部署 - 修改项目配置文件并快速应用到Tomcat中(即修改Tomcat war包中某个jar包中的配置文件)
-
如何将SpringBoot+Vue前后端分离项目一次打包为一个Jar包运行?