Spring-Boot打成war包(版本差异性)

目录

事例:

坑1:

最终解决: Spring-boot 的版本依赖以2.0基准

引申:

结论:


事例:


楼主最近开发新功能,运营同事要求打成war包方便他统一管理
于是“噩梦”由此展开

反复实验了网上的各种解决方案:
继承SpringBootServletInitializer,在pom.xml 文件中添加相应依赖等
但都无济于事。

坑1:


Spring-boot打的war包,但是无法访问?
正常的启动了项目但是无法访问。  
表现情况: 一直转圈儿。

运行web项目后,访问地址程序一直处于等待中,也没有报错

查询结果:
1.GC过长
2.内存占用过高,内存不够用
3.系统负载了

猜测:
在Spring-Boot 1.0 中针对打War运行的情况存在一些bug,在它高度封装的类内部出现了死循环等操作,导致无法访问最终访问超时


最终解决: Spring-boot 的版本依赖以2.0基准

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.1.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

详情: 
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

public class SpringBootStartApplication extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(SpringBootDemo281Application.class);
    }
}

VS

import org.springframework.boot.web.support.SpringBootServletInitializer;

public class SpringBootStartApplication extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(SpringBootDemo281Application.class);
    }
}

SpringBootServletInitializer 包的引用差别:是否有“servlet”路径。


引申:


===================================
“spring-boot-starter-parent”的作用
指定编码格式默认使用utf-8。
指定java版本默认使用1.8。
提供Dependency Management进行项目依赖的版本管理,如指定实际依赖的版本号(已经做版本兼容性测试)。
默认的资源过滤和插件管理。

===================================
myeclipse,源代码更改后,重新编译,执行,仍然执行的是原来的代码。

MyEclipse中的代码在 执行了 maven package 后回退了?


常见情况:
你启动该项目的内存不足时

MyEclipse自己存在的第二缓存??

====================================================================

java The type java.lang.String cannot be resolved. It is indirectly referenced from 

JDK1.8 版本有可能异常

==================================================================== 
Unable to find a single main class from the following candidates [com.roncoo.education.SpringBootDemo281Application, com.roncoo.example.SpringBootDemo281Application] -> [Help 1]
只能够有一个 SpringApplicationBoot

====================================================================

打war包时,怎么设置映射名称?
<build>
        <finalName>projectName</finalName>
</build>

====================================================================


结论:

发现了在提问/回答或者说明解决方案时,开发环境及重要组件版本声明的重要性。
划重点:随着版本的更迭导致的答案周期性失效问题,在我们的日常开发中显的尤为重要。

发布了205 篇原创文章 · 获赞 22 · 访问量 8万+

猜你喜欢

转载自blog.csdn.net/weixin_39966065/article/details/103667712