今天我开始了Gradle的春季启动项目:
springBootVersion = '1.4.1.BUILD-SNAPSHOT'
但是当为存储库编写Unittest时,由于加载数据而出现错误。
我已经在schema.sql
目录中有import.sql
和test/resources
,在这些脚本中有Spring boot init。
但似乎Hibernate试图通过运行org.hibernate.tool.hbm2ddl.SchemaExport : HHH000227: Running hbm2ddl schema export
来重新创建。
我尝试配置一些hibernates属性,但它不起作用。
2016-08-11 19:28:41.675 INFO 30221 --- [ main] c.d.a.h.repository.FooRepositoryTest : The following profiles are active: test
2016-08-11 19:28:41.745 INFO 30221 --- [ main] o.s.w.c.s.GenericWebApplicationContext : Refreshing org.springframework.web.context.support.GenericWebApplicationContext@50f6ac94: startup date [Thu Aug 11 19:28:41 ICT 2016]; root of context hierarchy
2016-08-11 19:28:44.766 INFO 30221 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [class org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$b8a47c63] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-08-11 19:28:44.842 INFO 30221 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cache.annotation.ProxyCachingConfiguration' of type [class org.springframework.cache.annotation.ProxyCachingConfiguration$$EnhancerBySpringCGLIB$$1b6b281] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-08-11 19:28:44.881 INFO 30221 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration' of type [class org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration$$EnhancerBySpringCGLIB$$f62a7725] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-08-11 19:28:45.115 INFO 30221 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'spring.cache-org.springframework.boot.autoconfigure.cache.CacheProperties' of type [class org.springframework.boot.autoconfigure.cache.CacheProperties] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-08-11 19:28:45.145 INFO 30221 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.cache.CacheManagerCustomizers' of type [class org.springframework.boot.autoconfigure.cache.CacheManagerCustomizers] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-08-11 19:28:45.164 INFO 30221 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.boot.autoconfigure.cache.GuavaCacheConfiguration' of type [class org.springframework.boot.autoconfigure.cache.GuavaCacheConfiguration$$EnhancerBySpringCGLIB$$4dc7afc2] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-08-11 19:28:45.248 INFO 30221 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'cacheManager' of type [class org.springframework.cache.guava.GuavaCacheManager] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-08-11 19:28:45.252 INFO 30221 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'cacheAutoConfigurationValidator' of type [class org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration$CacheManagerValidator] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2016-08-11 19:28:46.096 INFO 30221 --- [ main] o.s.jdbc.datasource.init.ScriptUtils : Executing SQL script from URL [file:/home/x/workspace/api/bin/schema.sql]
2016-08-11 19:28:46.133 INFO 30221 --- [ main] o.s.jdbc.datasource.init.ScriptUtils : Executed SQL script from URL [file:/home/x/workspace/api/bin/schema.sql] in 37 ms.
2016-08-11 19:28:46.161 INFO 30221 --- [ main] o.s.jdbc.datasource.init.ScriptUtils : Executing SQL script from URL [file:/home/x/workspace/api/bin/data.sql]
2016-08-11 19:28:46.162 INFO 30221 --- [ main] o.s.jdbc.datasource.init.ScriptUtils : Executed SQL script from URL [file:/home/x/workspace/api/bin/data.sql] in 1 ms.
2016-08-11 19:28:46.478 INFO 30221 --- [ main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2016-08-11 19:28:46.513 INFO 30221 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2016-08-11 19:28:46.667 INFO 30221 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.0.9.Final}
2016-08-11 19:28:46.669 INFO 30221 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2016-08-11 19:28:46.671 INFO 30221 --- [ main] org.hibernate.cfg.Environment : HHH000021: Bytecode provider name : javassist
2016-08-11 19:28:46.726 INFO 30221 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2016-08-11 19:28:47.147 INFO 30221 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2016-08-11 19:28:47.810 INFO 30221 --- [ main] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000227: Running hbm2ddl schema export
2016-08-11 19:28:47.818 INFO 30221 --- [ main] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000230: Schema export complete
2016-08-11 19:28:47.870 INFO 30221 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2016-08-11 19:28:49.208 INFO 30221 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/v2/api-docs],methods=[GET],produces=[application/json || application/hal+json]}" onto public org.springframework.http.ResponseEntity springfox.documentation.swagger2.web.Swagger2Controller.getDocumentation(java.lang.String,javax.servlet.http.HttpServletRequest)
2016-08-11 19:28:49.210 INFO 30221 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/configuration/security]}" onto org.springframework.http.ResponseEntity springfox.documentation.swagger.web.ApiResourceController.securityConfiguration()
2016-08-11 19:28:49.212 INFO 30221 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/swagger-resources]}" onto org.springframework.http.ResponseEntity> springfox.documentation.swagger.web.ApiResourceController.swaggerResources()
2016-08-11 19:28:49.212 INFO 30221 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/configuration/ui]}" onto org.springframework.http.ResponseEntity springfox.documentation.swagger.web.ApiResourceController.uiConfiguration()
2016-08-11 19:28:49.218 INFO 30221 --- [ 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-11 19:28:49.219 INFO 30221 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2016-08-11 19:28:49.632 INFO 30221 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/beans || /beans.json],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2016-08-11 19:28:49.633 INFO 30221 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/health || /health.json],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint.invoke(java.security.Principal)
2016-08-11 19:28:49.634 INFO 30221 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/autoconfig || /autoconfig.json],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2016-08-11 19:28:49.635 INFO 30221 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/env/{name:.*}],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint.value(java.lang.String)
2016-08-11 19:28:49.636 INFO 30221 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/env || /env.json],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2016-08-11 19:28:49.637 INFO 30221 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/heapdump || /heapdump.json],methods=[GET],produces=[application/octet-stream]}" onto public void org.springframework.boot.actuate.endpoint.mvc.HeapdumpMvcEndpoint.invoke(boolean,javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException,javax.servlet.ServletException
2016-08-11 19:28:49.638 INFO 30221 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/configprops || /configprops.json],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2016-08-11 19:28:49.639 INFO 30221 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/metrics/{name:.*}],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.MetricsMvcEndpoint.value(java.lang.String)
2016-08-11 19:28:49.639 INFO 30221 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/metrics || /metrics.json],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2016-08-11 19:28:49.642 INFO 30221 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/trace || /trace.json],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2016-08-11 19:28:49.645 INFO 30221 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/info || /info.json],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2016-08-11 19:28:49.646 INFO 30221 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/mappings || /mappings.json],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2016-08-11 19:28:49.647 INFO 30221 --- [ main] o.s.b.a.e.mvc.EndpointHandlerMapping : Mapped "{[/dump || /dump.json],methods=[GET],produces=[application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter.invoke()
2016-08-11 19:28:50.073 INFO 30221 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.web.context.support.GenericWebApplicationContext@50f6ac94: startup date [Thu Aug 11 19:28:41 ICT 2016]; root of context hierarchy
2016-08-11 19:28:50.137 INFO 30221 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-08-11 19:28:50.137 INFO 30221 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-08-11 19:28:50.188 INFO 30221 --- [ 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-11 19:28:50.835 INFO 30221 --- [ main] d.s.w.p.DocumentationPluginsBootstrapper : Context refreshed
2016-08-11 19:28:50.859 INFO 30221 --- [ main] d.s.w.p.DocumentationPluginsBootstrapper : Found 1 custom documentation plugin(s)
2016-08-11 19:28:50.872 INFO 30221 --- [ main] s.d.s.w.s.ApiListingReferenceScanner : Scanning for api listing references
2016-08-11 19:28:51.280 INFO 30221 --- [ main] c.d.a.h.repository.FooRepositoryTest : Started FooRepositoryTest in 10.174 seconds (JVM running for 10.888)
2016-08-11 19:28:51.404 INFO 30221 --- [ Thread-3] o.s.w.c.s.GenericWebApplicationContext : Closing org.springframework.web.context.support.GenericWebApplicationContext@50f6ac94: startup date [Thu Aug 11 19:28:41 ICT 2016]; root of context hierarchy
2016-08-11 19:28:51.426 INFO 30221 --- [ Thread-3] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2016-08-11 19:28:51.426 INFO 30221 --- [ Thread-3] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000227: Running hbm2ddl schema export
2016-08-11 19:28:51.439 INFO 30221 --- [ Thread-3] org.hibernate.tool.hbm2ddl.SchemaExport : HHH000230: Schema export complete
我的测试application-test.yml
:
spring:
datasource:
driverClassName: org.h2.Driver
url: jdbc:h2:mem:test_mem;MODE=MySQL
username: sa
password:
initialize: true
jpa:
show-sql: true
hibernate:
naming-strategy: org.hibernate.cfg.EJB3NamingStrategy
ddl-auto: none
hbm2ddl:
auto: none
properties:
hibernate.hbm2ddl.auto: none
我的测试用例:
@RunWith(SpringRunner.class)
@SpringBootTest
@ActiveProfiles("test")
public class FooRepositoryTest {
@Autowired
private FooRepository repository;
@Test
public void testFindOne() {
Item foo = repository.findOne(4110L);
assertThat(foo.getId()).isEqualTo(4110L);
}
}
非常感谢您的帮助。