参考了同事的文档,自己也写一篇文档。
同时,补充了一下,程序是如何运行的。
一:SSM框架
1.说明
SSM(Spring+SpringMVC+MyBatis)框架集由Spring、SpringMVC、MyBatis三个开源框架整合而成,常作为数据源较简单的web项目的框架。
2.每个框架的功能
二:新建项目
1.程序大纲
2.使用软件
IDEA
3.新建Maven项目
4.定位
5.设置maven
6.项目保存路径
三:到目前为止的效果
1.大纲
2.配置tomcat
3.clean install
4.运行效果
很奇怪,啥时候定位到index.jsp的呢。这个以后再研究。
5.web.xml
1 <!DOCTYPE web-app PUBLIC 2 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 3 "http://java.sun.com/dtd/web-app_2_3.dtd" > 4 5 <web-app> 6 <display-name>Archetype Created Web Application</display-name> 7 </web-app>
6.pom.xml
这个pom感觉有点繁。不过现在是生成的,就先原本粘贴了。
1 <?xml version="1.0" encoding="UTF-8"?> 2 3 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 5 <modelVersion>4.0.0</modelVersion> 6 7 <groupId>jun.it</groupId> 8 <artifactId>ssm</artifactId> 9 <version>1.0-SNAPSHOT</version> 10 <packaging>war</packaging> 11 12 <name>ssm Maven Webapp</name> 13 14 <url>http://www.example.com</url> 15 16 <properties> 17 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 18 <maven.compiler.source>1.7</maven.compiler.source> 19 <maven.compiler.target>1.7</maven.compiler.target> 20 </properties> 21 22 <dependencies> 23 <dependency> 24 <groupId>junit</groupId> 25 <artifactId>junit</artifactId> 26 <version>4.11</version> 27 <scope>test</scope> 28 </dependency> 29 </dependencies> 30 31 <build> 32 <finalName>ssm</finalName> 33 <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> 34 <plugins> 35 <plugin> 36 <artifactId>maven-clean-plugin</artifactId> 37 <version>3.0.0</version> 38 </plugin> 39 <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging --> 40 <plugin> 41 <artifactId>maven-resources-plugin</artifactId> 42 <version>3.0.2</version> 43 </plugin> 44 <plugin> 45 <artifactId>maven-compiler-plugin</artifactId> 46 <version>3.7.0</version> 47 </plugin> 48 <plugin> 49 <artifactId>maven-surefire-plugin</artifactId> 50 <version>2.20.1</version> 51 </plugin> 52 <plugin> 53 <artifactId>maven-war-plugin</artifactId> 54 <version>3.2.0</version> 55 </plugin> 56 <plugin> 57 <artifactId>maven-install-plugin</artifactId> 58 <version>2.5.2</version> 59 </plugin> 60 <plugin> 61 <artifactId>maven-deploy-plugin</artifactId> 62 <version>2.8.2</version> 63 </plugin> 64 </plugins> 65 </pluginManagement> 66 </build> 67 </project>
7.index.jsp
1 <html> 2 <body> 3 <h2>Hello World!</h2> 4 </body> 5 </html>
四:引入新的包
1.需要的最少的包
1 <?xml version="1.0" encoding="UTF-8"?> 2 3 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 5 <modelVersion>4.0.0</modelVersion> 6 7 <groupId>jun.it</groupId> 8 <artifactId>ssm</artifactId> 9 <version>1.0-SNAPSHOT</version> 10 <packaging>war</packaging> 11 12 <name>ssm Maven Webapp</name> 13 14 <url>http://www.example.com</url> 15 16 <properties> 17 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 18 <maven.compiler.source>1.7</maven.compiler.source> 19 <maven.compiler.target>1.7</maven.compiler.target> 20 <!--自己新添加的版本--> 21 <junit.version>4.11</junit.version> 22 <mybatis.version>3.4.6</mybatis.version> 23 <mysql.version>8.0.11</mysql.version> 24 <spring.version>5.0.4.RELEASE</spring.version> 25 <mybatis-spring.version>1.3.2</mybatis-spring.version> 26 <commons-dbpc.version>1.4</commons-dbpc.version> 27 </properties> 28 29 <dependencies> 30 <!--测试--> 31 <dependency> 32 <groupId>junit</groupId> 33 <artifactId>junit</artifactId> 34 <version>${junit.version}</version> 35 <scope>test</scope> 36 </dependency> 37 38 <!-- dbcp数据源 --> 39 <dependency> 40 <groupId>commons-dbcp</groupId> 41 <artifactId>commons-dbcp</artifactId> 42 <version>${commons-dbpc.version}</version> 43 </dependency> 44 45 <!--mysql的连接包--> 46 <!--JDBC Type 4 driver for MySQL--> 47 <dependency> 48 <groupId>mysql</groupId> 49 <artifactId>mysql-connector-java</artifactId> 50 <version>${mysql.version}</version> 51 </dependency> 52 53 <!-- Mybatis3.4.1 --> 54 <dependency> 55 <groupId>org.mybatis</groupId> 56 <artifactId>mybatis</artifactId> 57 <version>${mybatis.version}</version> 58 </dependency> 59 60 <!-- spring整合mybatis --> 61 <!--An easy-to-use Spring bridge for MyBatis sql mapping framework.--> 62 <dependency> 63 <groupId>org.mybatis</groupId> 64 <artifactId>mybatis-spring</artifactId> 65 <version>${mybatis-spring.version}</version> 66 </dependency> 67 68 <!-- spring核心包 --> 69 <!--spring-core--> 70 <dependency> 71 <groupId>org.springframework</groupId> 72 <artifactId>spring-core</artifactId> 73 <version>${spring.version}</version> 74 </dependency> 75 76 <!--Spring JDBC--> 77 <dependency> 78 <groupId>org.springframework</groupId> 79 <artifactId>spring-jdbc</artifactId> 80 <version>${spring.version}</version> 81 </dependency> 82 83 <!--Spring WebMVC--> 84 <dependency> 85 <groupId>org.springframework</groupId> 86 <artifactId>spring-webmvc</artifactId> 87 <version>${spring.version}</version> 88 </dependency> 89 90 <!--Spring Context--> 91 <dependency> 92 <groupId>org.springframework</groupId> 93 <artifactId>spring-context</artifactId> 94 <version>${spring.version}</version> 95 </dependency> 96 97 <!-- https://mvnrepository.com/artifact/commons-pool/commons-pool --> 98 <dependency> 99 <groupId>commons-pool</groupId> 100 <artifactId>commons-pool</artifactId> 101 <version>1.6</version> 102 </dependency> 103 104 <build> 105 <finalName>ssm</finalName> 106 <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> 107 <plugins> 108 <plugin> 109 <artifactId>maven-clean-plugin</artifactId> 110 <version>3.0.0</version> 111 </plugin> 112 <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging --> 113 <plugin> 114 <artifactId>maven-resources-plugin</artifactId> 115 <version>3.0.2</version> 116 </plugin> 117 <plugin> 118 <artifactId>maven-compiler-plugin</artifactId> 119 <version>3.7.0</version> 120 </plugin> 121 <plugin> 122 <artifactId>maven-surefire-plugin</artifactId> 123 <version>2.20.1</version> 124 </plugin> 125 <plugin> 126 <artifactId>maven-war-plugin</artifactId> 127 <version>3.2.0</version> 128 </plugin> 129 <plugin> 130 <artifactId>maven-install-plugin</artifactId> 131 <version>2.5.2</version> 132 </plugin> 133 <plugin> 134 <artifactId>maven-deploy-plugin</artifactId> 135 <version>2.8.2</version> 136 </plugin> 137 </plugins> 138 </pluginManagement> 139 <!----> 140 <resources> 141 <resource> 142 <directory>src/main/java</directory> 143 <includes> 144 <include>mapper/*.xml</include> 145 </includes> 146 </resource> 147 <resource> 148 <directory>src/main/resource</directory> 149 <includes> 150 <include>config/*</include> 151 </includes> 152 </resource> 153 </resources> 154 </build> 155 156 157 </project>
2.剩下的自己选择使用
1 <dependency> 2 <groupId>org.springframework</groupId> 3 <artifactId>spring-web</artifactId> 4 <version>${spring.version}</version> 5 </dependency> 6 <dependency> 7 <groupId>org.springframework</groupId> 8 <artifactId>spring-oxm</artifactId> 9 <version>${spring.version}</version> 10 </dependency> 11 <dependency> 12 <groupId>org.springframework</groupId> 13 <artifactId>spring-tx</artifactId> 14 <version>${spring.version}</version> 15 </dependency> 16 <dependency> 17 <groupId>org.springframework</groupId> 18 <artifactId>spring-aop</artifactId> 19 <version>${spring.version}</version> 20 </dependency> 21 <dependency> 22 <groupId>org.springframework</groupId> 23 <artifactId>spring-orm</artifactId> 24 <version>${spring.version}</version> 25 </dependency> 26 <dependency> 27 <groupId>org.springframework</groupId> 28 <artifactId>spring-beans</artifactId> 29 <version>${spring.version}</version> 30 </dependency> 31 <dependency> 32 <groupId>org.springframework</groupId> 33 <artifactId>spring-context-support</artifactId> 34 <version>${spring.version}</version> 35 </dependency> 36 <dependency> 37 <groupId>org.springframework</groupId> 38 <artifactId>spring-aspects</artifactId> 39 <version>${spring.version}</version> 40 </dependency> 41 <dependency> 42 <groupId>org.springframework</groupId> 43 <artifactId>spring-test</artifactId> 44 <version>${spring.version}</version> 45 </dependency>
五:开始创建MVC目录
1.原目录
2.在main节点下新建java和resource
在main上右键后,使用New Folder新建。
3.设置java与resource类型
4.创建如下java项目目录
只需要新建package就可以了。
action:存放Controller
dao:sql对应的接口
mapper:sql的xml文件
model:数据库实体类
service:就是service了
5.创建resource下的文件
先新建一个config目录,以及ssm需要的三个配置文件。
注意的是config不是package,是Directory。
spring的配置文件applicationContext.xml
spring MVC的配置文件springmvc-servlet.xml
数据库链接的配置文件jdbc.properties
六:配置文件以及web.xml的内容
1.applicationContext.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns="http://www.springframework.org/schema/beans" 5 xmlns:context="http://www.springframework.org/schema/context" 6 xsi:schemaLocation="http://www.springframework.org/schema/beans 7 http://www.springframework.org/schema/beans/spring-beans.xsd 8 http://www.springframework.org/schema/aop 9 http://www.springframework.org/schema/aop/spring-aop.xsd 10 http://www.springframework.org/schema/context 11 http://www.springframework.org/schema/context/spring-context.xsd 12 http://www.springframework.org/schema/tx 13 http://www.springframework.org/schema/tx/spring-tx.xsd 14 http://www.springframework.org/schema/cache 15 http://www.springframework.org/schema/cache/spring-cache.xsd"> 16 17 <!-- 自动扫描 --> 18 <context:component-scan base-package="service,dao,action"/> 19 <!-- 引入外置文件 --> 20 <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> 21 <property name="location" value="classpath:/config/jdbc.properties"/> 22 <!--这个配置告诉spring,当某个placeholder无法找到时,先不要报错,并尝试用另一个PropertyPlaceholderConfigurer来设置placeholder的值。--> 23 <property name="ignoreUnresolvablePlaceholders" value="true" /> 24 </bean> 25 26 <!--数据库连接池配置--> 27 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> 28 <property name="driverClassName" value="${jdbc.driver}"/> 29 <property name="url" value="${jdbc.url}"/> 30 <property name="username" value="${jdbc.username}"/> 31 <property name="password" value="${jdbc.password}"/> 32 </bean> 33 34 <bean name="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> 35 <property name="dataSource" ref="dataSource"/> 36 <property name="mapperLocations" value="classpath:/mapper/*.xml"/> 37 </bean> 38 39 <!-- 40 Mybatis-Spring为我们提供了一个实现了SqlSession接口的SqlSessionTemplate类,它是线程安全的,可以被多个Dao同时使用。 41 同时它还跟Spring的事务进行了关联,确保当前被使用的SqlSession是一个已经和Spring的事务进行绑定了的。 42 而且它还可以自己管理Session的提交和关闭。当使用了Spring的事务管理机制后,SqlSession还可以跟着Spring的事务一起提交和回滚。 43 --> 44 <bean id="sqlSessionTemplate" class="org.mybatis.spring.SqlSessionTemplate"> 45 <constructor-arg index="0" ref="sqlSessionFactory"/> 46 </bean> 47 48 </beans>
2.springmvc-servlet.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <beans xmlns="http://www.springframework.org/schema/beans" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xmlns:context="http://www.springframework.org/schema/context" 5 xmlns:mvc="http://www.springframework.org/schema/mvc" 6 xsi:schemaLocation="http://www.springframework.org/schema/beans 7 http://www.springframework.org/schema/beans/spring-beans.xsd 8 http://www.springframework.org/schema/context 9 http://www.springframework.org/schema/context/spring-context-4.3.xsd 10 http://www.springframework.org/schema/mvc 11 http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd"> 12 13 <!-- 自动扫描包,实现支持注解的IOC --> 14 <context:component-scan base-package="action" /> 15 16 <!-- Spring MVC不处理静态资源 --> 17 <mvc:default-servlet-handler /> 18 19 <!-- 支持mvc注解驱动 --> 20 <mvc:annotation-driven /> 21 22 <!-- 视图解析器 --> 23 <bean 24 class="org.springframework.web.servlet.view.InternalResourceViewResolver" 25 id="internalResourceViewResolver"> 26 <!-- 前缀 --> 27 <property name="prefix" value="/" /> 28 <!-- 后缀 --> 29 <property name="suffix" value=".jsp" /> 30 </bean> 31 32 </beans>
3.jdbc.properties
1 jdbc.driver=com.mysql.jdbc.Driver 2 jdbc.url=jdbc:mysql://127.0.0.1:3308/test?characterEncoding=utf8&useSSL=false&serverTimezone=GMT 3 jdbc.username=root 4 jdbc.password=123456
4.web.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xmlns="http://java.sun.com/xml/ns/javaee" 4 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 5 id="WebApp_ID" version="3.0"> 6 7 <welcome-file-list> 8 <welcome-file>index.jsp</welcome-file> 9 </welcome-file-list> 10 11 <!-- Spring容器启动监听器 --> 12 <listener> 13 <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 14 </listener> 15 <context-param> 16 <param-name>contextConfigLocation</param-name> 17 <param-value>classpath*:config/applicationContext.xml</param-value> 18 </context-param> 19 20 <servlet> 21 <servlet-name>springmvc</servlet-name> 22 <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 23 <init-param> 24 <!--Spring mvc配置文件路径 --> 25 <param-name>contextConfigLocation</param-name> 26 <param-value>classpath*:config/springmvc-servlet.xml</param-value> 27 </init-param> 28 <load-on-startup>1</load-on-startup> 29 </servlet> 30 <servlet-mapping> 31 <servlet-name>springmvc</servlet-name> 32 <url-pattern>/</url-pattern> 33 </servlet-mapping> 34 35 <!--编码过滤器 --> 36 <filter> 37 <filter-name>characterEncodingFilter</filter-name> 38 <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 39 <init-param> 40 <param-name>encoding</param-name> 41 <param-value>UTF-8</param-value> 42 </init-param> 43 <init-param> 44 <param-name>forceEncoding</param-name> 45 <param-value>true</param-value> 46 </init-param> 47 </filter> 48 <filter-mapping> 49 <filter-name>characterEncodingFilter</filter-name> 50 <url-pattern>/*</url-pattern> 51 </filter-mapping> 52 53 <context-param> 54 <param-name>spring.profiles.active</param-name> 55 <param-value>dev</param-value> 56 </context-param> 57 <context-param> 58 <param-name>spring.profiles.default</param-name> 59 <param-value>dev</param-value> 60 </context-param> 61 <context-param> 62 <param-name>spring.liveBeansView.mbeanDomain</param-name> 63 <param-value>dev</param-value> 64 </context-param> 65 66 </web-app>
七:对应关系(拷贝)
1.对应关系理解
八:测试程序
1.大纲
2.新建数据库
sql如下:
1 CREATE TABLE 2 student 3 ( 4 id INT(1), 5 name VARCHAR(20), 6 sex TINYINT(1), 7 address VARCHAR(50) 8 )
插入数据:
INSERT INTO student VALUES ('1', 'tom', '1', '1');
3.运行
输入网址:
http://localhost:8080/Hello/SayHello
4.效果
以后再做解析。
九:Java区域的程序
1.Student.java
几个字段的domain。
1 package model; 2 3 import java.io.Serializable; 4 5 public class Student implements Serializable { 6 private static final long serialVersionUID = 1L; 7 8 private int id; 9 private String name; 10 private boolean sex; 11 private String address; 12 13 public void setId(int id) { 14 this.id = id; 15 } 16 17 public void setName(String name) { 18 this.name = name; 19 } 20 21 public void setSex(boolean sex) { 22 this.sex = sex; 23 } 24 25 public void setAddress(String address) { 26 this.address = address; 27 } 28 29 public int getId() { 30 return id; 31 } 32 33 public String getName() { 34 return name; 35 } 36 37 public boolean isSex() { 38 return sex; 39 } 40 41 public String getAddress() { 42 return address; 43 } 44 45 @Override 46 public String toString() { 47 return "Student{" + 48 "id=" + id + 49 ", name='" + name + '\'' + 50 ", sex=" + sex + 51 ", address='" + address + '\'' + 52 '}'; 53 } 54 }
2.StudentDao.java
这个没有用到,dao的处理在service中处理了
1 package dao; 2 3 import model.Student; 4 5 public interface StudentDao { 6 /** 方法名对应Mapper中方法名 */ 7 // public Student getStudent(int id); 8 }
3.StudentService.java
1 package service; 2 3 import model.Student; 4 import org.mybatis.spring.SqlSessionTemplate; 5 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.stereotype.Controller; 7 8 @Controller 9 public class StudentService { 10 /** 11 *sqlSessionTemplate模板提供了sqlsession 12 */ 13 @Autowired 14 private SqlSessionTemplate sqlSessionTemplate; 15 public Student getStudent(int id) { 16 Student student = sqlSessionTemplate.selectOne("dao.StudentDao.getStudent", id); 17 return student; 18 } 19 }
4.HelloWorld.java
1 package action; 2 3 import org.springframework.beans.factory.annotation.Autowired; 4 import org.springframework.stereotype.Controller; 5 import org.springframework.ui.Model; 6 import org.springframework.web.bind.annotation.RequestMapping; 7 import service.StudentService; 8 9 @Controller 10 @RequestMapping("/Hello") 11 public class HelloWorld { 12 @Autowired 13 private StudentService studentService; 14 15 @RequestMapping("/SayHello") 16 public String SayHello(Model model) { 17 String student = studentService.getStudent(1).toString(); 18 System.out.println(student); 19 model.addAttribute("message", student); 20 // 对应页面名 21 return "/hello"; 22 } 23 }
5.StudentMapper.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <!DOCTYPE mapper 3 PUBLIC "-//mybatis.org//DTD mapper 3.0//EN" 4 "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> 5 <mapper namespace="dao.StudentDao"> 6 7 <select id="getStudent" parameterType="int" resultType="model.Student"> 8 SELECT * 9 FROM student 10 WHERE id = #{id} 11 </select> 12 13 </mapper>
十:在过程中遇到的几个奇葩的问题
1.缺少common-pool
控制台:
1 21-Jul-2018 23:12:39.887 警告 [RMI TCP Connection(3)-127.0.0.1] org.springframework.context.support.AbstractApplicationContext.refresh Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'studentService': Unsatisfied dependency expressed through field 'sqlSessionTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionTemplate' defined in URL [file:/E:/IDEA_Test/SSM/target/ssm/WEB-INF/classes/config/applicationContext.xml]: Cannot resolve reference to bean 'sqlSessionFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in URL [file:/E:/IDEA_Test/SSM/target/ssm/WEB-INF/classes/config/applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.apache.commons.dbcp.BasicDataSource] from ClassLoader [ParallelWebappClassLoader 2 context: ROOT 3 delegate: false 4 ----------> Parent Classloader: 5 java.net.URLClassLoader@1c4af82c 6 ] 7 21-Jul-2018 23:12:39.890 严重 [RMI TCP Connection(3)-127.0.0.1] org.springframework.web.context.ContextLoader.initWebApplicationContext Context initialization failed 8 org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'studentService': Unsatisfied dependency expressed through field 'sqlSessionTemplate'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionTemplate' defined in URL [file:/E:/IDEA_Test/SSM/target/ssm/WEB-INF/classes/config/applicationContext.xml]: Cannot resolve reference to bean 'sqlSessionFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in URL [file:/E:/IDEA_Test/SSM/target/ssm/WEB-INF/classes/config/applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.apache.commons.dbcp.BasicDataSource] from ClassLoader [ParallelWebappClassLoader 9 context: ROOT 10 delegate: false 11 ----------> Parent Classloader: 12 java.net.URLClassLoader@1c4af82c 13 ] 14 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:587) 15 at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:91) 16 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:373) 17 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1344) 18 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) 19 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502) 20 at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312) 21 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) 22 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) 23 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) 24 at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760) 25 at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:868) 26 at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) 27 at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:409) 28 at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:291) 29 at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103) 30 at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4745) 31 at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5207) 32 at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 33 at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752) 34 at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728) 35 at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734) 36 at org.apache.catalina.startup.HostConfig.manageApp(HostConfig.java:1739) 37 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 38 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 39 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 40 at java.lang.reflect.Method.invoke(Method.java:498) 41 at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300) 42 at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) 43 at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) 44 at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:482) 45 at org.apache.catalina.mbeans.MBeanFactory.createStandardContext(MBeanFactory.java:431) 46 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 47 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 48 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 49 at java.lang.reflect.Method.invoke(Method.java:498) 50 at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:300) 51 at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) 52 at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) 53 at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468) 54 at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76) 55 at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309) 56 at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401) 57 at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829) 58 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 59 at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 60 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 61 at java.lang.reflect.Method.invoke(Method.java:498) 62 at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357) 63 at sun.rmi.transport.Transport$1.run(Transport.java:200) 64 at sun.rmi.transport.Transport$1.run(Transport.java:197) 65 at java.security.AccessController.doPrivileged(Native Method) 66 at sun.rmi.transport.Transport.serviceCall(Transport.java:196) 67 at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:568) 68 at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:826) 69 at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:683) 70 at java.security.AccessController.doPrivileged(Native Method) 71 at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:682) 72 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) 73 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) 74 at java.lang.Thread.run(Thread.java:748) 75 Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionTemplate' defined in URL [file:/E:/IDEA_Test/SSM/target/ssm/WEB-INF/classes/config/applicationContext.xml]: Cannot resolve reference to bean 'sqlSessionFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in URL [file:/E:/IDEA_Test/SSM/target/ssm/WEB-INF/classes/config/applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.apache.commons.dbcp.BasicDataSource] from ClassLoader [ParallelWebappClassLoader 76 context: ROOT 77 delegate: false 78 ----------> Parent Classloader: 79 java.net.URLClassLoader@1c4af82c 80 ] 81 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:378) 82 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:110) 83 at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:622) 84 at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:148) 85 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1270) 86 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1127) 87 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) 88 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502) 89 at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312) 90 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) 91 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) 92 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) 93 at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251) 94 at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138) 95 at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065) 96 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:584) 97 ... 60 more 98 Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in URL [file:/E:/IDEA_Test/SSM/target/ssm/WEB-INF/classes/config/applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.apache.commons.dbcp.BasicDataSource] from ClassLoader [ParallelWebappClassLoader 99 context: ROOT 100 delegate: false 101 ----------> Parent Classloader: 102 java.net.URLClassLoader@1c4af82c 103 ] 104 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:378) 105 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:110) 106 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1613) 107 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1357) 108 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) 109 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502) 110 at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312) 111 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) 112 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) 113 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) 114 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:367) 115 ... 75 more 116 Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Lookup method resolution failed; nested exception is java.lang.IllegalStateException: Failed to introspect Class [org.apache.commons.dbcp.BasicDataSource] from ClassLoader [ParallelWebappClassLoader 117 context: ROOT 118 delegate: false 119 [2018-07-21 11:12:39,951] Artifact SSM:war exploded: Error during artifact deployment. See server log for details. 120 ----------> Parent Classloader: 121 java.net.URLClassLoader@1c4af82c 122 ] 123 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:262) 124 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1198) 125 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1123) 126 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) 127 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:502) 128 at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:312) 129 at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) 130 at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:310) 131 at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) 132 at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:367) 133 ... 85 more 134 Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.apache.commons.dbcp.BasicDataSource] from ClassLoader [ParallelWebappClassLoader 135 context: ROOT 136 delegate: false 137 ----------> Parent Classloader: 138 java.net.URLClassLoader@1c4af82c 139 ] 140 at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:659) 141 at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:556) 142 at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:541) 143 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:245) 144 ... 94 more 145 Caused by: java.lang.NoClassDefFoundError: org/apache/commons/pool/KeyedObjectPoolFactory 146 at java.lang.Class.getDeclaredMethods0(Native Method) 147 at java.lang.Class.privateGetDeclaredMethods(Class.java:2701) 148 at java.lang.Class.getDeclaredMethods(Class.java:1975) 149 at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:641) 150 ... 97 more 151 Caused by: java.lang.ClassNotFoundException: org.apache.commons.pool.KeyedObjectPoolFactory 152 at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1291) 153 at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119) 154 ... 101 more
2.SSL
1 21-Jul-2018 23:16:01.133 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [D:\apache-tomcat-8.5.23\webapps\manager] has finished in [36] ms 2 Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary. 3 Sat Jul 21 23:16:04 CST 2018 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore for server certificate verification.
解决方式
jdbc.url=jdbc:mysql://127.0.0.1:3308/test?characterEncoding=utf8&useSSL=false
3.时区问题
1 Type Exception Report 2 3 Message Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 4 5 Description The server encountered an unexpected condition that prevented it from fulfilling the request. 6 7 Exception 8 9 org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 10 ### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.) 11 ### The error may exist in file [E:\IDEA_Test\SSM\target\ssm\WEB-INF\classes\mapper\StudentMapper.xml] 12 ### The error may involve dao.StudentDao.getStudent 13 ### The error occurred while executing a query 14 ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.) 15 org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:986) 16 org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:870) 17 javax.servlet.http.HttpServlet.service(HttpServlet.java:635) 18 org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855) 19 javax.servlet.http.HttpServlet.service(HttpServlet.java:742) 20 org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 21 org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) 22 org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 23 Root Cause 24 25 org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 26 ### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.) 27 ### The error may exist in file [E:\IDEA_Test\SSM\target\ssm\WEB-INF\classes\mapper\StudentMapper.xml] 28 ### The error may involve dao.StudentDao.getStudent 29 ### The error occurred while executing a query 30 ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.) 31 org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:77) 32 org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:446) 33 com.sun.proxy.$Proxy16.selectOne(Unknown Source) 34 org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:166) 35 service.StudentService.getStudent(StudentService.java:16) 36 action.HelloWorld.SayHello(HelloWorld.java:17) 37 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 38 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 39 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 40 java.lang.reflect.Method.invoke(Method.java:498) 41 org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209) 42 org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) 43 org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) 44 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:870) 45 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:776) 46 org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) 47 org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991) 48 org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) 49 org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978) 50 org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:870) 51 javax.servlet.http.HttpServlet.service(HttpServlet.java:635) 52 org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855) 53 javax.servlet.http.HttpServlet.service(HttpServlet.java:742) 54 org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 55 org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) 56 org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 57 Root Cause 58 59 org.apache.ibatis.exceptions.PersistenceException: 60 ### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.) 61 ### The error may exist in file [E:\IDEA_Test\SSM\target\ssm\WEB-INF\classes\mapper\StudentMapper.xml] 62 ### The error may involve dao.StudentDao.getStudent 63 ### The error occurred while executing a query 64 ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.) 65 org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) 66 org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150) 67 org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141) 68 org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:77) 69 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 70 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 71 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 72 java.lang.reflect.Method.invoke(Method.java:498) 73 org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433) 74 com.sun.proxy.$Proxy16.selectOne(Unknown Source) 75 org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:166) 76 service.StudentService.getStudent(StudentService.java:16) 77 action.HelloWorld.SayHello(HelloWorld.java:17) 78 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 79 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 80 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 81 java.lang.reflect.Method.invoke(Method.java:498) 82 org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209) 83 org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) 84 org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) 85 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:870) 86 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:776) 87 org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) 88 org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991) 89 org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) 90 org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978) 91 org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:870) 92 javax.servlet.http.HttpServlet.service(HttpServlet.java:635) 93 org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855) 94 javax.servlet.http.HttpServlet.service(HttpServlet.java:742) 95 org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 96 org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) 97 org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 98 Root Cause 99 100 org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.) 101 org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:81) 102 org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:82) 103 org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:68) 104 org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:338) 105 org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:84) 106 org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62) 107 org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:326) 108 org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) 109 org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) 110 org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83) 111 org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148) 112 org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141) 113 org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:77) 114 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 115 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 116 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 117 java.lang.reflect.Method.invoke(Method.java:498) 118 org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433) 119 com.sun.proxy.$Proxy16.selectOne(Unknown Source) 120 org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:166) 121 service.StudentService.getStudent(StudentService.java:16) 122 action.HelloWorld.SayHello(HelloWorld.java:17) 123 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 124 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 125 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 126 java.lang.reflect.Method.invoke(Method.java:498) 127 org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209) 128 org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) 129 org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) 130 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:870) 131 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:776) 132 org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) 133 org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991) 134 org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) 135 org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978) 136 org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:870) 137 javax.servlet.http.HttpServlet.service(HttpServlet.java:635) 138 org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855) 139 javax.servlet.http.HttpServlet.service(HttpServlet.java:742) 140 org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 141 org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) 142 org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 143 Root Cause 144 145 org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support.) 146 org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1549) 147 org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388) 148 org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044) 149 org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:151) 150 org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:115) 151 org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:78) 152 org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:82) 153 org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:68) 154 org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:338) 155 org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:84) 156 org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62) 157 org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:326) 158 org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) 159 org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) 160 org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83) 161 org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148) 162 org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141) 163 org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:77) 164 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 165 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 166 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 167 java.lang.reflect.Method.invoke(Method.java:498) 168 org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433) 169 com.sun.proxy.$Proxy16.selectOne(Unknown Source) 170 org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:166) 171 service.StudentService.getStudent(StudentService.java:16) 172 action.HelloWorld.SayHello(HelloWorld.java:17) 173 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 174 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 175 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 176 java.lang.reflect.Method.invoke(Method.java:498) 177 org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209) 178 org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) 179 org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) 180 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:870) 181 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:776) 182 org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) 183 org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991) 184 org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) 185 org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978) 186 org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:870) 187 javax.servlet.http.HttpServlet.service(HttpServlet.java:635) 188 org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855) 189 javax.servlet.http.HttpServlet.service(HttpServlet.java:742) 190 org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 191 org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) 192 org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 193 Root Cause 194 195 java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support. 196 com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:127) 197 com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:95) 198 com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:87) 199 com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:61) 200 com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:71) 201 com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:76) 202 com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:862) 203 com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:444) 204 com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:230) 205 com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:226) 206 org.apache.commons.dbcp.DriverConnectionFactory.createConnection(DriverConnectionFactory.java:38) 207 org.apache.commons.dbcp.PoolableConnectionFactory.makeObject(PoolableConnectionFactory.java:582) 208 org.apache.commons.dbcp.BasicDataSource.validateConnectionFactory(BasicDataSource.java:1556) 209 org.apache.commons.dbcp.BasicDataSource.createPoolableConnectionFactory(BasicDataSource.java:1545) 210 org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1388) 211 org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044) 212 org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:151) 213 org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:115) 214 org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:78) 215 org.mybatis.spring.transaction.SpringManagedTransaction.openConnection(SpringManagedTransaction.java:82) 216 org.mybatis.spring.transaction.SpringManagedTransaction.getConnection(SpringManagedTransaction.java:68) 217 org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:338) 218 org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:84) 219 org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62) 220 org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:326) 221 org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) 222 org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) 223 org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83) 224 org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148) 225 org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141) 226 org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:77) 227 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 228 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 229 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 230 java.lang.reflect.Method.invoke(Method.java:498) 231 org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:433) 232 com.sun.proxy.$Proxy16.selectOne(Unknown Source) 233 org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:166) 234 service.StudentService.getStudent(StudentService.java:16) 235 action.HelloWorld.SayHello(HelloWorld.java:17) 236 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 237 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 238 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 239 java.lang.reflect.Method.invoke(Method.java:498) 240 org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209) 241 org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) 242 org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) 243 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:870) 244 org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:776) 245 org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) 246 org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991) 247 org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) 248 org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978) 249 org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:870) 250 javax.servlet.http.HttpServlet.service(HttpServlet.java:635) 251 org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:855) 252 javax.servlet.http.HttpServlet.service(HttpServlet.java:742) 253 org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) 254 org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) 255 org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) 256 Root Cause
解决方式:
jdbc.url=jdbc:mysql://127.0.0.1:3308/test?characterEncoding=utf8&useSSL=false&serverTimezone=GMT