移动到application.properties时,系统属性将停止生效

时间:2015-07-21 02:08:36

标签: spring hibernate spring-boot spring-data

我有一个Spring Boot应用程序,它使用Spring Data和Hibernate进行数据访问。我最初遇到了很长的应用程序启动时间。因此,基于此answer,我设置了' hibernate.temp.use_jdbc_metadata_defaults'到'假'作为系统属性(-D)。应用程序启动时间问题已解决。

现在,我将该配置从系统属性移动到application.properties。延迟的应用程序启动问题已经恢复。

我的application.properties:

hibernate.temp.use_jdbc_metadata_defaults=false
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=none
spring.datasource.validation-query=SELECT 1
spring.datasource.testOnBorrow=true
spring.datasource.testWhileIdle=true

设置" org.springframework.core.env" to" DEBUG"记录,我看到该属性是从application.properties解析的(如预期的那样)。

INFO   | jvm 1    | 2015/07/20 19:47:15 | 19:47:15.211 [WrapperJarAppMain] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Found key 'spring.jpa.database-platform' in [applicationConfig: [classpath:/application.properties]] with type [String] and value 'org.hibernate.dialect.PostgreSQLDialect'
...
INFO   | jvm 1    | 2015/07/20 19:47:15 | 19:47:15.226 [WrapperJarAppMain] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Found key 'hibernate.temp.use_jdbc_metadata_defaults' in [applicationConfig: [classpath:/application.properties]] with type [String] and value 'false'
...
INFO   | jvm 1    | 2015/07/20 19:47:15 | 19:47:15.229 [WrapperJarAppMain] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Found key 'spring.jpa.hibernate.ddl-auto' in [applicationConfig: [classpath:/application.properties]] with type [String] and value 'none'

在延迟启动期间,应用程序在特定点停止然后恢复。当它停止时," jstack" JVM给出了以下结果:

INFO   | jvm 1    | 2015/07/20 19:47:58 | "WrapperJarAppMain" #20 prio=5 os_prio=0 tid=0x00007fb1ec02b800 nid=0x1d39 runnable [0x00007fb248257000]
INFO   | jvm 1    | 2015/07/20 19:47:58 |    java.lang.Thread.State: RUNNABLE
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at java.net.SocketInputStream.socketRead0(Native Method)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at java.net.SocketInputStream.read(SocketInputStream.java:170)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at java.net.SocketInputStream.read(SocketInputStream.java:141)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.postgresql.core.VisibleBufferedInputStream.readMore(VisibleBufferedInputStream.java:143)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.postgresql.core.VisibleBufferedInputStream.ensureBytes(VisibleBufferedInputStream.java:112)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.postgresql.core.VisibleBufferedInputStream.read(VisibleBufferedInputStream.java:71)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.postgresql.core.PGStream.ReceiveChar(PGStream.java:282)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1803)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       - locked <0x000000077a9f8ca0> (a org.postgresql.core.v3.QueryExecutorImpl)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:570)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:420)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.postgresql.jdbc2.TypeInfoCache.getPGType(TypeInfoCache.java:323)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       - locked <0x000000077aa00ce0> (a org.postgresql.jdbc2.TypeInfoCache)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.postgresql.jdbc2.TypeInfoCache.getSQLType(TypeInfoCache.java:175)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.postgresql.jdbc2.TypeInfoCache.requiresQuoting(TypeInfoCache.java:711)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.postgresql.jdbc2.AbstractJdbc2DatabaseMetaData.getTypeInfo(AbstractJdbc2DatabaseMetaData.java:4002)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.hibernate.engine.jdbc.spi.TypeInfo.extractTypeInfo(TypeInfo.java:101)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:163)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1887)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1845)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:852)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:845)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:844)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       - locked <0x00000006dc2676d0> (a java.util.concurrent.ConcurrentHashMap)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:956)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:747)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       - locked <0x00000006dbd48650> (a java.lang.Object)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:686)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.springframework.boot.SpringApplication.run(SpringApplication.java:320)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.springframework.boot.SpringApplication.run(SpringApplication.java:957)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.springframework.boot.SpringApplication.run(SpringApplication.java:946)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at xyz.abc.AppApplication.main(AppApplication.java:10)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at java.lang.reflect.Method.invoke(Method.java:497)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:53)
INFO   | jvm 1    | 2015/07/20 19:47:58 |       at java.lang.Thread.run(Thread.java:745)
INFO   | jvm 1    | 2015/07/20 19:47:58 |

来自&#34; org.postgresql.jdbc2.TypeInfoCache.getSQLType&#34; (在上面的堆栈中),我认为Hibernate仍在尝试加载元数据。这与我的配置相反。

我很感激有关如何将配置从系统属性移动到application.properties的任何指示都会导致它无法生效?

2 个答案:

答案 0 :(得分:6)

要指定不在默认 override func scrollViewDidScroll(scrollView: UIScrollView) { //1. decide on the distance from the bottom that if the user scrolls to that point you will load more results let minimumTrigger = scrollView.bounds.size.height + self.triggerDistanceFromBottom // 2. Now you are checking to see that the height of all the content in the scrollview/tableView.( i.e. all the cells hights stacked ontop of eachother) is greater than the minimum height for triggering a load // This step is so that if you have only a few results, the loadMoreResults method won't constantly be called. if scrollView.contentSize.height > minimumTrigger { //3. This calculated the distance from the bottom of the scrollview. let distanceFromBottom = scrollView.contentSize.height - (scrollView.bounds.size.height - scrollView.contentInset.bottom) - scrollView.contentOffset.y //4. then this is the crucial check. if distanceFromBottom < self.scrollTriggerDistanceFromBottom { // Do your stuff } } } 预期属性中的任何属性,请使用spring.jpa

所以而不是

spring.jpa.properties.<your-property-name-here>

hibernate.temp.use_jdbc_metadata_defaults=false

中使用此功能
application.properties

Spring Boot参考指南的this section中对此进行了解释。

答案 1 :(得分:0)

spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false

将以上内容添加到spring项目中的application.properties文件中