SpringBoot开发问题汇总

1.SpringDataJPA不自动建表

需要在application.yml中配置jpa : ddl-auto: update

server:
  port: 8088
  tomcat:
    uri-encoding: utf-8
spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/mwpf?serverTimezone=GMT%2B8
    username: root
    password: beiyang
  jpa:
    database: MySQL
    database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
    show-sql: true
    hibernate:
      ddl-auto: update

2.异常退出导致端口占用

使用cmd结束占用8080端口的进程
1 打开cmd输入:netstat -ano|findstr 8080,显示占用8080的进程;
image
2 可以查看8080下的各个进程的具体信息,例如通过netstat -ano|findstr 4252查看PID为3160的进程具体的信息,然后使用taskkill /pid 3160/f将进程关闭,我们可以将8080下的进程全给关掉,然后在运行Spring Boot项目,就不会出现端口占用问题了!

netstat -ano|findstr 8080
taskkill /pid 3160/f

3.解决Error resolving template template might not exist or might not be accessible问题

thymeleaf + Spring Boot 在开发环境正常,但用jar运行时报错 Error resolving template template might not exist or might not be accessible;

这个问题我们都很好明白,就是模板页不存在,但是实际上它能找到模板页,但是在使用th:include标签的时候才会出错,这就是问题的症结所在。

其实这个问题也很好解决,我们只需要在引用模板文件的时候不用”/”打头就可以了,通过类似相对路径的方式来引用,但是需要说明的是,这里的相对路径仍然是相对于模板根目录来做的。

@RequestMapping("/view")
public String view()  {
    return "/view";
}

改成

@RequestMapping("/view")
public String view()  {
    return "view";
}

就可以了

posted @ 2021-06-04 15:42  牵着毛驴唱着歌  阅读(168)  评论(0)    收藏  举报