开发工具STS
情况1:
用STS中集成的Maven install生产程序jar包时候,报错Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin
分析解决:
是因为STS工具默认配置的Installed JREs是jre不是jdk
解决方法:
STS-->Window-->Preferences-->搜索jre,找到如下图,将JRE改成JDK目录。重新install成功
情况2:
项目中使用Value注解,给变量赋yml文件的值要注意属性节点的级数
比如@Value("${cupSize}"),指的就是一级属性
情况3:
使用chrome浏览器的postman测试,只要在浏览器输入chrome://apps/,就可以调用出来。
情况4:
springboot工程,删除了Application类
用JUnit测试,报错
Consider defining a bean of type 'com.ggeit.pay.properties.ParaProperties' in your configuration.
Field paraProperties in com.ggeit.pay.impl.Payimpl required a bean of type 'com.ggeit.pay.properties.ParaProperties' that could not be found.
原因就是没有Application类,没有@SpringBootApplication,被预先执行
情况5:
springboot工程,支持jsp, springboot用的是2.0.3版本,处理有如下
a.public class AggPayWebAppApplication extends SpringBootServletInitializer
//要使用tomcat来支持加载JSP必须继承SpringBootServletInitializer类并重写其中configure方法
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(this.getClass());
}
b.在src\main\下增加webapp目录,如图
c.pom.xml新增
依赖
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ggeit.pay</groupId>
<artifactId>agg-pay-web-app</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>agg-pay-web-app</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- 需要这个版本号才知道JSP,Jar模式下访问 -->
<version>1.4.2.RELEASE</version>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/webapp</directory>
<targetPath>resources</targetPath>
<includes>
<include>**/**</include>
</includes>
</resource>
</resources>
</build>
</project>
d.静态资源添加
情况6:
将程序打包成war,放到tomcat 7.0 ,jdk1.7下使用
a.pom.xml修改
<packaging>war</packaging>
<version>1.5.9.RELEASE</version>---为了对应jdk1.7
<java.version>1.7</java.version>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
Java Build Path 改成jdk1.7
出现报错选择maven-update projects
b.maven install报错
Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test (default-test) on project agg-pay-web:
原因:部分jdk1.7对maven支持的bug
解决方法,下载了高版本64位jdk1.7,同时设置Windows的JDK环境变量是1.7
c.war包部署后网页无法打开
原因是HTML里没有写全结束标签如
<link rel="stylesheet" href="../lib/css/bootstrap.min.css">
解决方法1
<link rel="stylesheet" href="../lib/css/bootstrap.min.css"/>
解决方法2
pom.xml新增
<dependency>
<groupId>net.sourceforge.nekohtml</groupId>
<artifactId>nekohtml</artifactId>
</dependency>
yml文件增加
spring:
thymeleaf:
mode: LEGACYHTML5
d.jdk1.7下 maven clean失败
小窍门,把项目都改回JDK1.8,clean后改回来
e.jdk1.7,tomcat7,跑War,本来Jar下跑没有问题的中文,在Get模式下都乱码
解决方法,tomcat的server.xml添加URIEncoding="UTF-8"
<Connector port="8008" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8"/>
f.Jar改War之后,所有的资源访问路径,http路径需要加上包名
window.location.href = "/aggpay/lay/tips?tips="+"支付成功!";
$.post("/aggpay/data/dowxpay",
aggpay是war包名
情况7:
sts创建spring boot项目时,出现 JSONException: A JSONObject text must begin with '{' at character 0
解决方法:只需要将url换为https://start.spring.io即可,原来是http://start.spring.io