前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Spring Boot遇到的某些问题

Spring Boot遇到的某些问题

作者头像
Dream城堡
发布2018-09-10 12:42:25
7520
发布2018-09-10 12:42:25
举报
文章被收录于专栏:Spring相关Spring相关

Spring Boot遇到的某些问题

1.关于templates的html包格式问题:

代码语言:javascript
复制
<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <spring-cloud.version>Finchley.RELEASE</spring-cloud.version>
        <!--以下两项需要如果不配置,解析themleaft 会有问题-->
        <thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
        <thymeleaf-layout-dialect.version>2.0.5</thymeleaf-layout-dialect.version>
    </properties>

Tomcat配置Context 标签以后Tomcat启动不了

因为项目要访问本地硬盘的文件所以要去Tomcat的server.xml里配置Context ,

<Context path="/image" docBase="F:\file\image" debug="0" reloadable="true"></Context>

结果弄了一个多小时发现是docBase的路径不存在。因为我们是上传文件才会建立文件夹,导致一直找不到问题出在哪,记录一下

2.关于thymeleaf引入js.Css等:

代码语言:javascript
复制
<head th:fragment="header">

  <meta charset="UTF-8" />

  <title th:text="#{head.title}"></title>

  <meta name="viewport" content="width=device-width, initial-scale=1" />

  <link rel="shortcut icon" th:href="@{/static/img/favicon.gif}" type="image/gif" />

  <link rel="stylesheet" th:href="@{/resources/css/bootstrap.min.css}" />

  <link rel="stylesheet" th:href="@{/resources/css/jquery.ui.all.css}" />

<link rel="stylesheet" th:href="@{/resources/css/jquery.ui.customer.css}" />

  <script th:src="@{/resources/js/jquery-1.9.1.min.js}"></script>

  <script th:src="@{/resource/js/bootstrap.min.js}"></script>

</head>

下面在你要的页面 引入这个片段就行<head th:include="theme/fragments::header" /> 他就相当于jsp 中我们常用的<%@ include file="/WEB-INF/jsp/public/header.jspf"%>

3.如果静态资源被拦截或者不生效,请尝试以下配置:

增加配置类:

代码语言:javascript
复制
package com.home.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

@Configuration
public class MyWebMvcConfigurerAdapter extends WebMvcConfigurerAdapter {
    /**
     * 配置静态访问资源
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        super.addResourceHandlers(registry);
    }
}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018.08.19 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Spring Boot遇到的某些问题
    • 1.关于templates的html包格式问题:
      • 2.关于thymeleaf引入js.Css等:
        • 3.如果静态资源被拦截或者不生效,请尝试以下配置:
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档