1 项目出现错误:The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path
解决:这是项目没有配置服务器路径,把服务器的路径配置到项目里就可以了
2 出现错误:java.sql.SQLNonTransientConnectionException: Public Key Retrieval is not allowed
解决:在连接数据库的url中,加上allowPublicKeyRetrieval=true
3 完成spring boot的热部署
解决:在实际项目开发中,发现每次修改文件都得重新启动spring boot项目,这太影响开发效率了,如何不用重新启动spring boot,就能自动更新项目? 只需要在pom.xml中添加下面依赖就可以了。
<!-- 实现spring boot热部署 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
4 使spring boot支持JSP显示
解决:在src/main目录下创建webapp目录,将jsp页面放在这个目录下面。然后在application.properties文件中添加下面属性:
#JSP
spring.mvc.view.prefix=/
spring.mvc.view.suffix=.jsp
最后在controller包下创建控制类的映射方法即可。(浏览器输入:http://localhost:8080/index)
package com.demo.controller;
import java.text.DateFormat;
import java.util.Date;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HelloController {
@RequestMapping("/index")
public String hello(Model m){
m.addAttribute("now",DateFormat.getDateTimeInstance().format(new Date()));
return "index"; //视图重定向index.jsp
}
}
5 maven的pom.xml中添加spring data jpa的依赖包,报错:java.sql.SQLException: Access denied for user ‘’@‘localhost’ (using password: YES)
原因:application.properties文件中spring.datasource.username属性配置成了spring.datasource.data-username,改成前者即可。
6 出现错误:spring boot jpa-java.lang.IllegalArgumentException: Not a managed type
原因:实体类没有标注@Entity注解,只标了@Table。
7 只用某个类有注解@Component,才能自动装配(@Autowired)里面的字段,这个字段也需要是@Component
8 Thymeleaf相关
- 当确定项目使用Thymeleaf,则可能出现页面显示不正常。比如:如果html页面没有使用任何thymeleaf的东西,但仍然显示不正常。这是因为JavaScript脚本存在[[]]等特殊符号,这时需要在javascript中添加
th:inline="none"
,即<script type="text/javascript" th:inline="none">
,这样JavaScript代码才不会被thymeleaf影响。
9 echart的图表随着浏览器大小进行缩放
解决:在JavaScript代码最后填入下面代码
window.addEventListener("resize",function(){
myChart.resize();
myChart2.resize();
myChart3.resize(); //myChart指自己定义的echartsDom对象
});
myChart
为你的echart对象。