Spring Boot遇到的某些问题

简介: Spring Boot遇到的某些问题1.关于templates的html包格式问题: UTF-8 UTF-8 1.8 Finchley.RELEASE 3.0.2.RELEASE 2.0.5 Tomcat配置Context 标签以后Tomcat启动不了因为项目要访问本地硬盘的文件所以要去Tomcat的server.xml里配置Context ,结果弄了一个多小时发现是docBase的路径不存在。

Spring Boot遇到的某些问题

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

<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等:

<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.如果静态资源被拦截或者不生效,请尝试以下配置:

增加配置类:

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);
    }
}
相关文章
|
22天前
|
Java 应用服务中间件 Maven
SpringBoot 项目瘦身指南
SpringBoot 项目瘦身指南
38 0
|
1天前
|
安全 Java 应用服务中间件
江帅帅:Spring Boot 底层级探索系列 03 - 简单配置
江帅帅:Spring Boot 底层级探索系列 03 - 简单配置
4 0
江帅帅:Spring Boot 底层级探索系列 03 - 简单配置
|
3天前
|
XML Java C++
【Spring系列】Sping VS Sping Boot区别与联系
【4月更文挑战第2天】Spring系列第一课:Spring Boot 能力介绍及简单实践
28 0
【Spring系列】Sping VS Sping Boot区别与联系
|
2月前
|
XML 监控 druid
【Java专题_02】springboot+mybatis+pagehelper分页插件+druid数据源详细教程
【Java专题_02】springboot+mybatis+pagehelper分页插件+druid数据源详细教程
|
3月前
|
Java
springboot项目打包瘦身
springboot项目打包瘦身
|
5月前
|
Java 测试技术
Springboot集成JUnit5优雅进行单元测试
Springboot集成JUnit5优雅进行单元测试
|
安全 Java Maven
Spring Boot资源文件问题总结(Spring Boot的静态资源访问,配置文件外置)
Spring Boot资源文件问题总结(Spring Boot的静态资源访问,配置文件外置)
1295 1
|
9月前
|
Java Maven
【Springboot】创建boot工程spring-boot-maven-plugin报红、出错_解决方案
【Springboot】创建boot工程spring-boot-maven-plugin报红、出错_解决方案
313 0
|
9月前
|
SQL druid 前端开发
让SpringBoot不需要Controller、Service、DAO、Mapper,卧槽!这款工具绝了!
让SpringBoot不需要Controller、Service、DAO、Mapper,卧槽!这款工具绝了!
|
11月前
|
Java C++ Spring
Spring Boot - ConfigDataEnvironmentPostProcessor(Boot 2.4)搞定配置文件加载优先级
Spring Boot - ConfigDataEnvironmentPostProcessor(Boot 2.4)搞定配置文件加载优先级
236 0