1、添加完相关jar包,写完配置文件,写完测试类,运行提示
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
这个是因为jdbcurl配置要改为
jdbcUrl=jdbc:mysql://localhost:3306/gss?useUnicode=true&characterEncoding=utf8&useSSL=true
2、继续运行报如下错误:
org.hibernate.exception.GenericJDBCException: Cannot open connection Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database! Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
网上大多解决方案都是检查数据库连接 驱动 用户名 密码是否正确 附上我的配置:
jdbcUrl=jdbc:mysql://localhost:3306/gss?useUnicode=true&characterEncoding=utf8&useSSL=true driverClass=com.mysql.jdbc.Driver user=root password=root initialPoolSize=10 maxPoolSize=30
3、依然报上面的错误,N Hours后发现是mysql驱动jar包问题,用的6.0.2,换成5.1.32就可以了
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.32</version> </dependency>
4、解决Failed to load class "org.slf4j.impl.StaticLoggerBinder"
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
官网上刊登的解决办法是:
This error is reported when the org.slf4j.impl.StaticLoggerBinder class could not be loaded into memory. This happens when no appropriate SLF4J binding could be found on the class path. Placing one (and only one) of slf4j-nop.jar, slf4j-simple.jar, slf4j-log4j12.jar, slf4j-jdk14.jar or logback-classic.jar on the class path should solve the problem.
其实就是添加一个叫做slf4j-log4j12-1.5.11.jar的包进行转换就可以了,注意版本号。
5、 Intellij配置完xml后找不到xml,但是按CTRL又能点击过去
ERROR [RMI TCP Connection(3)-127.0.0.1] ContextLoader:351 - Context initialization failed org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from relative location [cn/god/nsfw/user/conf/user-spring.xml] Offending resource: class path resource [applicationContext.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from URL [file:/D:/javaCode/projects/tax/target/god/WEB-INF/classes/cn/god/nsfw/user/conf/user-spring.xml]; nested exception is java.io.FileNotFoundException: D:javaCodeprojects ax argetgodWEB-INFclassescngod sfwuserconfuser-spring.xml (系统找不到指定的路径。)
这个需要把xml所在文件夹设置成Resource就可以了。
6、测试hibernate自动建表,报错
Hibernate: insert into news_table (title, content) values (?, ?) Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not insert: [org.crazyit.app.domain.News] …………此处省略 Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'hibernate.news_table' doesn't exist …………此处省略
<property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
把这行换成:
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
但是不知道为什么。。。。。