RuoYi-Vue-v3.9.0:前端打包dist放入jar包不分离部署
·
单体小项目,简化部署,故将前端打包dist,放入jar包,进行不分离部署。
后端修改
1.ResourcesConfig.java
framework/config/ResourcesConfig.java
增加代码:



具体代码如下:
/** 本地文件上传路径 */
registry.addResourceHandler(Constants.RESOURCE_PREFIX + "/**")
.addResourceLocations("file:" + RuoYiConfig.getProfile() + "/")
.addResourceLocations(new ClassPathResource("/static/static/index.html") {
@Override
public Resource createRelative(String relativePath) {
return this;
}
});
/** 页面静态化 */
registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/static/");
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/index").setViewName("index.html");
registry.addViewController("/").setViewName("index.html");
registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
}
config.setAllowCredentials(true);
2.SecurityConfig
framework/config/SecurityConfig

.antMatchers(HttpMethod.GET, "/", "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/static/**","/index","/profile/**").permitAll()
3.pom.xml

具体代码
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<excludes>
<exclude>static/**</exclude>
</excludes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>static/**</include>
</includes>
</resource>
</resources>
前端修改
1..env.development

2..env.production

3.index.js

4.package.json

5.vue.config.js

打包验证

直接浏览器访问后端地址:http://localhost:8080/
参考:
RuoYi vue 前后端分离版本合并打成一个jar包,不通过nginx访问前端 - 简书
https://www.jianshu.com/p/e1aa1cdd54b8
更多推荐



所有评论(0)