Some problems encountered by Spring Boot

Keywords: Front-end Thymeleaf Spring Java Tomcat

Some problems encountered by Spring Boot

1. About html package format of templates:

<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>
        <!--The following two items need to be resolved if they are not configured themleaft There will be problems.-->
        <thymeleaf.version>3.0.2.RELEASE</thymeleaf.version>
        <thymeleaf-layout-dialect.version>2.0.5</thymeleaf-layout-dialect.version>
    </properties>

Tomcat can't start after Tomcat configures the Context tag

Because the project is accessing files on the local hard disk, it is necessary to configure Context in Tomcat's server.xml.

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

As a result, it took more than an hour to find that docBase's path did not exist. Because we upload files to create folders, so we can not find the problem. Record it.

2. About thymeleaf introducing js.Css and so on:

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

Next, introduce this fragment into the page you want <head th: include= "theme/fragments:: header"/> which is equivalent to <%@ include file="/WEB-INF/jsp/public/header.jspf"%> which is commonly used in jsp.

3. If static resources are intercepted or not in effect, try the following configuration:

Add configuration classes:

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 {
    /**
     * Configuring static access resources
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        super.addResourceHandlers(registry);
    }
}

Posted by marlonbtx on Sun, 03 Feb 2019 00:54:15 -0800