为了找到解决方案,我已阅读了很多帖子。我想请求帮助找到问题。下面是application.properties配置文件和带有错误消息的输出。
aplication.properties:
# DATASOURCE
spring.datasource.url=jdbc:mysql://localhost:3306/hibernatedb
spring.datasource.name=hibernatedb
spring.datasource.username=nunit
spring.datasource.password=nunit
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
# CONTAINER
server.port=8080
server.context-path=/nunit/api
# JPA
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.show_sql=true
spring.jpa.hibernate.format_sql=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
spring.jpa.show-sql=true
# JDBC.X
db.driverClassName=com.mysql.jdbc.Driver
db.url=jdbc:mysql://localhost:3306;databaseName=hibernatedb
db.user=nunit
db.pass=nunit
# HIBERNATE.X
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.hbm2ddl.auto=create-drop
hibernate.
# SECURITY
security.basic.enabled=true
# HTTP REQUEST
spring.mvc.dispatch-options-request=true
# CORS configuration
endpoints.cors.allowed-origins=*
endpoints.cors.allowed-headers=*
endpoints.cors.allowed-methods=*
endpoints.cors.mapping=/**
#JACKSON
spring.jackson.date-format=MM/dd/yyyy
spring.jackson.serialization.write_dates_as_timestamps=false
控制台输出:
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.3.5.RELEASE)
2016-08-13 19:30:19.656 INFO 3868 --- [ main] com.nunit.NUnitServices : Starting NUnitServices on iNViNCiBLe with PID 3868 (C:\Users\nUnit\workspace_neon\nUnitServices\target\classes started by nUnit in C:\Users\nUnit\workspace_neon\nUnitServices)
2016-08-13 19:30:19.656 INFO 3868 --- [ main] com.nunit.NUnitServices : No active profile set, falling back to default profiles: default
2016-08-13 19:30:19.794 INFO 3868 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@140e5a13: startup date [Sat Aug 13 19:30:19 EEST 2016]; root of context hierarchy
2016-08-13 19:30:23.766 INFO 3868 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$673436dd] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-08-13 19:30:25.120 INFO 3868 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2016-08-13 19:30:25.162 INFO 3868 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2016-08-13 19:30:25.165 INFO 3868 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.0.33
2016-08-13 19:30:25.482 INFO 3868 --- [ost-startStop-1] o.a.c.c.C.[.[localhost].[/nunit/api] : Initializing Spring embedded WebApplicationContext
2016-08-13 19:30:25.483 INFO 3868 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 5689 ms
2016-08-13 19:30:26.626 INFO 3868 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-08-13 19:30:26.627 INFO 3868 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'hiddenHttpMethodFilter' to: [/*]
2016-08-13 19:30:26.628 INFO 3868 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'httpPutFormContentFilter' to: [/*]
2016-08-13 19:30:26.628 INFO 3868 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'requestContextFilter' to: [/*]
2016-08-13 19:30:26.632 INFO 3868 --- [ost-startStop-1] .e.DelegatingFilterProxyRegistrationBean : Mapping filter: 'springSecurityFilterChain' to: [/*]
2016-08-13 19:30:26.632 INFO 3868 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2016-08-13 19:30:27.367 INFO 3868 --- [ost-startStop-1] b.a.s.AuthenticationManagerConfiguration :
Using default security password: f5fc04b8-ea2e-4a37-b3c2-8cc4b439ea9b
2016-08-13 19:30:27.491 INFO 3868 --- [ost-startStop-1] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: Ant [pattern='/css/**'], []
2016-08-13 19:30:27.491 INFO 3868 --- [ost-startStop-1] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: Ant [pattern='/js/**'], []
2016-08-13 19:30:27.492 INFO 3868 --- [ost-startStop-1] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: Ant [pattern='/images/**'], []
2016-08-13 19:30:27.492 INFO 3868 --- [ost-startStop-1] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: Ant [pattern='/**/favicon.ico'], []
2016-08-13 19:30:27.492 INFO 3868 --- [ost-startStop-1] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: Ant [pattern='/error'], []
2016-08-13 19:30:27.653 INFO 3868 --- [ost-startStop-1] o.s.s.web.DefaultSecurityFilterChain : Creating filter chain: org.springframework.boot.autoconfigure.security.SpringBootWebSecurityConfiguration$ApplicationNoWebSecurityConfigurerAdapter$1@6a07267e, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@31e38a81, org.springframework.security.web.context.SecurityContextPersistenceFilter@489f333f, org.springframework.security.web.header.HeaderWriterFilter@47e64ac4, org.springframework.security.web.csrf.CsrfFilter@59f36eca, org.springframework.security.web.authentication.logout.LogoutFilter@716af3b4, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@71a82ef, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@3131177c, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@1732285a, org.springframework.security.web.session.SessionManagementFilter@615c6f88, org.springframework.security.web.access.ExceptionTranslationFilter@1a4e3459]
2016-08-13 19:30:28.258 INFO 3868 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2016-08-13 19:30:28.289 INFO 3868 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2016-08-13 19:30:28.455 INFO 3868 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {4.3.11.Final}
2016-08-13 19:30:28.458 INFO 3868 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2016-08-13 19:30:28.461 INFO 3868 --- [ main] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2016-08-13 19:30:28.871 INFO 3868 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
2016-08-13 19:30:29.631 ERROR 3868 --- [ main] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool.
java.sql.SQLException: Access denied for user 'nunit '@'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:871) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4323) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1267) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2255) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2286) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2085) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:795) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_102]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_102]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_102]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_102]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:404) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:400) ~[mysql-connector-java-5.1.38.jar:5.1.38]
42 more ...
2016-08-13 19:30:29.636 WARN 3868 --- [ main] o.h.e.jdbc.internal.JdbcServicesImpl : HHH000342: Could not obtain connection to query metadata : Access denied for user 'nunit '@'localhost' (using password: YES)
2016-08-13 19:30:29.656 INFO 3868 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
2016-08-13 19:30:29.680 INFO 3868 --- [ main] o.h.e.jdbc.internal.LobCreatorBuilder : HHH000422: Disabling contextual LOB creation as connection was null
2016-08-13 19:30:30.237 INFO 3868 --- [ main] o.h.h.i.ast.ASTQueryTranslatorFactory : HHH000397: Using ASTQueryTranslatorFactory
2016-08-13 19:30:30.500 INFO 3868 --- [ main] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000228: Running hbm2ddl schema update
2016-08-13 19:30:30.500 INFO 3868 --- [ main] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000102: Fetching database metadata
2016-08-13 19:30:30.500 ERROR 3868 --- [ main] o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool.
java.sql.SQLException: Access denied for user 'nunit '@'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:871) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4323) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1267) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2255) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2286) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2085) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:795) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_102]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_102]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_102]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_102]
at com.mysql.jdbc.Util.handleNewInstance(Util.java:404) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:400) ~[mysql-connector-java-5.1.38.jar:5.1.38]
41 more ...
2016-08-13 19:30:30.516 ERROR 3868 --- [ main] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000319: Could not get database metadata
java.sql.SQLException: Access denied for user 'nunit '@'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:871) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4323) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1267) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2255) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2286) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2085) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:795) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_102]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_102]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_102]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_102]
43 more ...
2016-08-13 19:30:30.516 ERROR 3868 --- [ main] org.hibernate.tool.hbm2ddl.SchemaUpdate : HHH000299: Could not complete schema update
java.sql.SQLException: Access denied for user 'nunit '@'localhost' (using password: YES)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:871) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:4323) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1267) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2255) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2286) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2085) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:795) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:44) ~[mysql-connector-java-5.1.38.jar:5.1.38]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_102]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_102]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_102]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_102]
43 more ...
2016-08-13 19:30:31.055 INFO 3868 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@140e5a13: startup date [Sat Aug 13 19:30:19 EEST 2016]; root of context hierarchy
2016-08-13 19:30:31.288 INFO 3868 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/services/helloWorld],methods=[POST]}" onto public java.util.List<com.nunit.rest.Message> com.nunit.rest.ServiceController.postHelloWorldMessage()
2016-08-13 19:30:31.291 INFO 3868 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/services/helloWorld]}" onto public java.util.List<com.nunit.rest.Message> com.nunit.rest.ServiceController.getHelloWorldMessage()
2016-08-13 19:30:31.297 INFO 3868 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2016-08-13 19:30:31.298 INFO 3868 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2016-08-13 19:30:31.381 INFO 3868 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-08-13 19:30:31.382 INFO 3868 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-08-13 19:30:31.506 INFO 3868 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-08-13 19:30:32.129 INFO 3868 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2016-08-13 19:30:32.339 INFO 3868 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2016-08-13 19:30:32.352 INFO 3868 --- [ main] com.nunit.NUnitServices : Started NUnitServices in 13.541 seconds (JVM running for 14.527)
答案 0 :(得分:0)
看起来您正在编写如此多的配置行,这应该足以连接到您的数据库。无需告诉Hibernate使用MySql方言既不自己配置Hibernate和JDBC:
spring.datasource.url=jdbc:mysql://localhost:3306/hibernatedb
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.username=nunit
spring.datasource.password=nunit
然后您可以尝试启用其他设置,如SQL日志,数据库初始化等等:
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.show_sql=true
spring.jpa.hibernate.format_sql=true
spring.jpa.show-sql=true
答案 1 :(得分:0)
在我阅读了这篇文章here后,我可以在添加此属性entitymanager.packagesToScan
和正确的扫描包后解决此问题。