Springboot的jar包和war包的区别

  • 转自: https://blog.csdn.net/qq_32331073/article/details/81544061
  • SpringBoot默认支持很多模板引擎,但是JSP只能够在War中使用,同时mvc.view.prifix/suffix必须主动配置给出,另外必须导入JSP的默认渲染servlet:"org.apache.jasper.servlet.JspServlet",即添加依赖:

  •     <dependency>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-jasper</artifactId>
            <scope>provided</scope>
        </dependency>
     
     
    • 1
    • 2
    • 3
    • 4
    • 5
  • 无论是Jar还是War都能够使用嵌套容器,java -jar来独立运行

  • 但只有war才能部署到外部容器中,且war中必须包含:"src/main/webapp/WEB-INF/web.xml"
  • SpringBoot中JSP模板引擎具备使用限制:
    • jsp不能够在jar中使用
    • Udertow容器不支持Jsp
    • 自定义的error.jsp错误页面并不能够复写默认的error handling view,如果你想要自定义错误页面,请尝试其他模板引擎Custom error pages
  • 如果你将项目打包成jar,就不要使用src/main/webapp目录,尽管该目录也是一个公共标准,但是它仅仅在war中有效,因为生成jar的构建工具将会自动把该目录忽略

  • Do not use the src/main/webapp directory if your application is packaged as a jar. Although this directory is a common standard, it works only with war packaging, and it is silently ignored by most build tools if you generate a jar.

  • SpringBoot的欢迎页同时支持静态资源模板引擎,如果项目中不存在" "、"/"Handling,那么将优先查看静态资源位置中是否存在index.html,否则才会查看index模板,如果都不存在将使用默认欢迎页

  • Spring Boot supports both static and templated welcome pages. It first looks for an index.html file in the configured static content locations. If one is not found, it then looks for an index template. If either is found, it is automatically used as the welcome page of the application.

  • Spring5.+中与SpringMVC担负对作用的SpringWebFlux并不是完全依赖于Servlet API,所以不能将它打包成war更不能使用src/main/webapp目录

  • Spring WebFlux applications do not strictly depend on the Servlet API, so they cannot be deployed as war files and do not use the src/main/webappdirectory.

  • 用户能够直接访问src/main/webapp中的静态资源,但并不能直接访问src/main/resources中的静态资源,但是Spring提供了ResourceHttpRequestHandler来配置src/main/resources(classpath)下指定访问目录

  • MVC中Interceptor只能够拦截Handlingsrc/main/webapp中的静态资源,对src/main/resources中的静态资源无效
  • 默认状态下,用户不具备src/main/webapp/WEB-INF的直接访问权限,但是可以通过程序中forwardredirect达到间接访问的目的,所以war项目中通常会将需要控制权限的资源文件放入到WEB-INF
  • 另外可见:Spring工程访问src/main/resources与src/main/webapp下静态资源的区别
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值