spring ----> 搭建spring+springmvc+mybatis出现的几个问题

环境:

idea ce 2018.1+maven3.5.3+mysql8.0.11+jdk1.8

spring4.3.7+spring mvc4.3.7+mybatis3.4.1+tomcat7.0.47(插件)

出现问题:

1、class path resource [xxxxxxxxx] cannot be opened because it does not exist(已经解决,下面见)

2、 No mapping found for HTTP request with URI [xxxxx] in DispatcherServlet with name 'DispatcherServlet'(问题未能复现,未能解决)

3、数据库连接池链接不上,具体描述如下:

Fri Jun 01 11:33:22 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.

解决:

在高版本的mysql中需要使用SSL,在jdbc.url中加上"&useSSL=false"

4、java.sql.SQLException: Unknown system variable 'query_cache_size'

数据库版本和驱动版本不一致冲突

解决:

引入8.0.11的驱动包

1    <!--mysql数据库驱动 -->
2         <dependency>
3             <groupId>mysql</groupId>
4             <artifactId>mysql-connector-java</artifactId>
5             <version>8.0.11</version>
6         </dependency>

5、java.sql.SQLException: The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone. 

服务器时区没被识别或者多个时区同时存在

解决:

在jdbc.url加上"&serverTimezone=UTC"

备注:

utc 协调世界时

北京与UTC的时差均为+8,也就是UTC+8

-----------------------------------------------------------分割线-----------------------------------------------------------

 问题1和2:

src/main/resources ??????

classpath ??????

/WEB-INF/ ?????

描述:

1)、db.properties、applicationContext-mybatis.xml和applicationContext-springmvc.xml放在这里(src/main/resources)不起作用,

web.xml配置: classpath:applicationContext-mybatis.xml /  classpath:applicationContext-springmvc.xml /  classpath:db.properties

报错:class path resource [applicationContext-mybatis.xml] cannot be opened because it does not exist

说明idea没有扫描到以.properties和.xml结尾的文件

解决:

在pom.xml中加入下面代码:

 1  <build>
 2         <finalName>Idea</finalName>
 3 
 4             <!--扫描到xml文件-->
 5             <resources>
 6                 <resource>
 7                     <directory>src/main/java</directory>
 8                     <includes>
 9                         <include>**/*.xml</include>
10                     </includes>
11                 </resource>
12                 <resource>
13                     <directory>src/main/resources</directory>
14                     <includes>
15                         <include>**/*.xml</include>
16                         <include>**/*.properties</include>
17                     </includes>
18                 </resource>
19             </resources>
20     </build>

可查看target文件下有相应的文件生成:

2)改变web.xml配置: classpath*:applicationContext-mybatis.xml /  classpath*:applicationContext-springmvc.xml /  classpath*:db.properties

上述文件位置还是放在src/main/resources中

idea有扫描到以.properties和.xml结尾的文件,但是报错:

org.springframework.web.servlet.PageNotFound noHandlerFound

警告: No mapping found for HTTP request with URI [/showUser/1] in DispatcherServlet with name 'DispatcherServlet'()(问题未能复现,未能解决)

3)、applicationContext-mybatis.xml和applicationContext-springmvc.xml放在/WEB-INF/ , db.properties放在src/main/resources中,以上能正常运行。

applicationContext-mybatis.xml中配置:

1 <context:property-placeholder location="classpath*:db.properties"/>

或者:

1 <context:property-placeholder location="classpath:db.properties"/>

 maven工程用到的依赖:

  1     <properties>
  2         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  3         <maven.compiler.source>1.8</maven.compiler.source>
  4         <maven.compiler.target>1.8</maven.compiler.target>
  5         <spring.version>4.3.7.RELEASE</spring.version>
  6         <mybatis.version>3.4.1</mybatis.version>
  7     </properties>
  8 
  9     <dependencies>
 10         <dependency>
 11             <groupId>junit</groupId>
 12             <artifactId>junit</artifactId>
 13             <version>4.11</version>
 14             <scope>test</scope>
 15         </dependency>
 16  
 17         <dependency>
 18             <groupId>org.springframework</groupId>
 19             <artifactId>spring-core</artifactId>
 20             <version>${spring.version}</version>
 21         </dependency>
 22 
 23         <dependency>
 24             <groupId>org.springframework</groupId>
 25             <artifactId>spring-beans</artifactId>
 26             <version>${spring.version}</version>
 27         </dependency>
 28 
 29         <dependency>
 30             <groupId>org.springframework</groupId>
 31             <artifactId>spring-context</artifactId>
 32             <version>${spring.version}</version>
 33         </dependency>
 34 
 35         <dependency>
 36             <groupId>org.springframework</groupId>
 37             <artifactId>spring-jdbc</artifactId>
 38             <version>${spring.version}</version>
 39         </dependency>
 40 
 41         <dependency>
 42             <groupId>org.springframework</groupId>
 43             <artifactId>spring-tx</artifactId>
 44             <version>${spring.version}</version>
 45         </dependency>
 46 
 47         <dependency>
 48             <groupId>org.springframework</groupId>
 49             <artifactId>spring-web</artifactId>
 50             <version>${spring.version}</version>
 51         </dependency>
 52 
 53         <dependency>
 54             <groupId>org.springframework</groupId>
 55             <artifactId>spring-webmvc</artifactId>
 56             <version>${spring.version}</version>
 57         </dependency>
 58 
 59         <dependency>
 60             <groupId>org.springframework</groupId>
 61             <artifactId>spring-test</artifactId>
 62             <version>${spring.version}</version>
 63         </dependency>
 64 
 65         <dependency>
 66             <groupId>org.aspectj</groupId>
 67             <artifactId>aspectjweaver</artifactId>
 68             <version>1.8.9</version>
 69         </dependency>
 70 
 71         <dependency>
 72             <groupId>mysql</groupId>
 73             <artifactId>mysql-connector-java</artifactId>
 74             <version>8.0.11</version>
 75         </dependency>
 76 
 77        <!-- <dependency>
 78             <groupId>mysql</groupId>
 79             <artifactId>mysql-connector-java</artifactId>
 80             <version>5.1.38</version>
 81         </dependency>-->
 82 
 83         <dependency>
 84             <groupId>org.apache.logging.log4j</groupId>
 85             <artifactId>log4j-core</artifactId>
 86             <version>2.6.1</version>
 87         </dependency>
 88 
 89         <dependency>
 90             <groupId>org.mybatis</groupId>
 91             <artifactId>mybatis</artifactId>
 92             <version>${mybatis.version}</version>
 93         </dependency>
 94 
 95         <dependency>
 96             <groupId>org.mybatis</groupId>
 97             <artifactId>mybatis-spring</artifactId>
 98             <version>1.3.1</version>
 99         </dependency>
100 
101         <dependency>
102             <groupId>com.mchange</groupId>
103             <artifactId>c3p0</artifactId>
104             <version>0.9.5.2</version>
105         </dependency>
106 
107         <!--<dependency>
108             <groupId>javax</groupId>
109             <artifactId>javaee-api</artifactId>
110             <version>7.0</version>
111         </dependency>-->
112 
113  <!--       <dependency>
114             <groupId>jstl</groupId>
115             <artifactId>jstl</artifactId>
116             <version>1.2</version>
117         </dependency>
118         <dependency>
119             <groupId>javax.servlet</groupId>
120             <artifactId>javax.servlet-api</artifactId>
121             <version>3.0.1</version>
122             <scope>provided</scope>
123         </dependency>
124         <dependency>
125             <groupId>javax.servlet.jsp</groupId>
126             <artifactId>jsp-api</artifactId>
127             <version>2.1</version>
128             <scope>provided</scope>
129         </dependency>-->
130     </dependencies>

 备注:

有个问题未解决

猜你喜欢

转载自www.cnblogs.com/mrray1105/p/9118878.html