Guest User

Untitled

a guest
Aug 21st, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.20 KB | None | 0 0
  1. <bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
  2. <property name="dataSourceClassName" value="com.sybase.jdbc4.jdbc.SybDataSource" />
  3.  
  4. <property name="connectionTestQuery" value="SELECT 1" />
  5. <property name="maximumPoolSize" value="100" />
  6. <property name="idleTimeout" value="60000" />
  7. <property name="jdbcUrl"
  8. value="jdbc:sybase:Tds:${hostname}:${port}/${dbname}" />
  9. <property name="username" value="${username}" />
  10. <property name="password" value="${password}" />
  11. </bean>
  12.  
  13.  
  14. <bean id="ds" class="com.zaxxer.hikari.HikariDataSource"
  15. destroy-method="close">
  16. <constructor-arg ref="hikariConfig" />
  17. </bean>
  18.  
  19. <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
  20. <property name="dataSource">
  21. <ref bean="ds" />
  22. </property>
  23. </bean>
  24.  
  25. Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ds' defined in class path resource [commons/config/datasourceTest.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.zaxxer.hikari.HikariDataSource]: Constructor threw exception; nested exception is com.zaxxer.hikari.pool.PoolInitializationException: Exception during pool initialization
  26. at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:288)
  27. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1051)
  28. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:955)
  29. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:490)
  30. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:461)
  31. at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
  32. at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
  33. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
  34. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
  35. at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
  36. at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
  37. at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
  38. at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:120)
  39. at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
  40. at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:100)
  41. at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:248)
  42. at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64)
  43. at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91)
  44. ... 25 more
  45. Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.zaxxer.hikari.HikariDataSource]: Constructor threw exception; nested exception is com.zaxxer.hikari.pool.PoolInitializationException: Exception during pool initialization
  46. at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:163)
  47. at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:121)
  48. at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:280)
  49. ... 42 more
  50. Caused by: com.zaxxer.hikari.pool.PoolInitializationException: Exception during pool initialization
  51. at com.zaxxer.hikari.pool.BaseHikariPool.initializeConnections(BaseHikariPool.java:544)
  52. at com.zaxxer.hikari.pool.BaseHikariPool.<init>(BaseHikariPool.java:171)
  53. at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:60)
  54. at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:48)
  55. at com.zaxxer.hikari.HikariDataSource.<init>(HikariDataSource.java:80)
  56. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
  57. at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
  58. at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
  59. at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
  60. at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)
  61. ... 44 more
  62. Caused by: java.sql.SQLException: JZ0PN: Specified port number of -1 was out of range. Port numbers must meet the following conditions: 0 <= portNumber <= 65535
  63. at com.sybase.jdbc4.jdbc.SybConnection.getAllExceptions(Unknown Source)
  64. at com.sybase.jdbc4.jdbc.SybConnection.handleSQLE(Unknown Source)
  65. at com.sybase.jdbc4.jdbc.SybConnection.a(Unknown Source)
  66. at com.sybase.jdbc4.jdbc.SybConnection.handleHAFailover(Unknown Source)
  67. at com.sybase.jdbc4.jdbc.SybConnection.<init>(Unknown Source)
  68. at com.sybase.jdbc4.jdbc.SybDriver.createConnection(Unknown Source)
  69. at com.sybase.jdbc4.jdbc.SybDriver.connect(Unknown Source)
  70. at com.sybase.jdbc4.jdbc.SybDriver.connect(Unknown Source)
  71. at com.sybase.jdbc4.jdbc.SybDataSource.getConnection(Unknown Source)
  72. at com.zaxxer.hikari.pool.BaseHikariPool.addConnection(BaseHikariPool.java:438)
  73. at com.zaxxer.hikari.pool.BaseHikariPool.initializeConnections(BaseHikariPool.java:542)
  74. ... 53 more
  75.  
  76. public class JdbcTemplateFactoryTest {
  77.  
  78. @Autowired
  79. HikariConfig hikariConfig;
  80.  
  81. //@Autowired
  82. //HikariDataSource ds;
  83.  
  84.  
  85. @Test
  86. public void hikaritest(){
  87.  
  88. HikariDataSource ds = new HikariDataSource(hikariConfig);
  89. JdbcTemplate jdbcTemplate = new JdbcTemplate(ds);
  90.  
  91. assertNotNull(jdbcTemplate);
  92. }
  93. }
  94.  
  95. private Properties additionalProperties() throws CoParticipacaoException {
  96. Properties properties;
  97.  
  98. try {
  99. LOGGER.info("BEGIN");
  100. properties = new Properties();
  101.  
  102. LOGGER.info("Using adicional Hibernate properties:");
  103.  
  104. // properties.setProperty("hibernate.hbm2ddl.auto", "create-drop");
  105. properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
  106. properties.setProperty("spring.jpa.properties.hibernate.jdbc.time_zone", "UTC");
  107. properties.setProperty("spring.datasource.driver-class-name", "com.mysql.cj.jdbc.Driver");
  108. properties.setProperty("spring.jpa.datasource.driver-class-name", "com.mysql.cj.jdbc.Driver");
  109. properties.setProperty("spring.datasource.driver-class", "com.mysql.cj.jdbc.Driver");
  110. properties.setProperty("hibernate.connection.driver_class", "com.mysql.cj.jdbc.Driver");
  111.  
  112. properties.setProperty("spring.datasource.hikari.driverClassName", "com.mysql.cj.jdbc.Driver");
  113. properties.setProperty("spring.datasource.hikari.dataSourceClassName", "com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
  114.  
  115. properties.setProperty("spring.jpa.show-sql", "true");
  116. properties.setProperty("spring.jpa.hibernate.format_sql", "true");
  117. // properties.setProperty("spring.jpa.hibernate.ddl-auto",
  118. // "update");
  119. properties.setProperty("spring.jpa.properties.hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
  120. properties.setProperty("spring.jpa.hibernate.naming-strategy", "org.hibernate.cfg.ImprovedNamingStrategy");
  121.  
  122. LOGGER.info("END");
  123. return properties;
  124. } catch (Exception e) {
  125. LOGGER.error(e.getMessage(), e);
  126. throw new CoParticipacaoException(e);
  127. }
  128. }
  129.  
  130. @Primary
  131. @Bean
  132. public DataSource dataSource() throws Exception {
  133. JndiDataSourceLookup dataSourceLookup;
  134. DataSource dataSource;
  135. HikariDataSource hikariDataSource;
  136. HikariConfig hikariConfig;
  137.  
  138. try {
  139. LOGGER.info("BEGIN");
  140. LOGGER.info("Creating DataSource");
  141.  
  142. dataSourceLookup = new JndiDataSourceLookup();
  143. dataSourceLookup.setResourceRef(true);
  144. dataSource = dataSourceLookup.getDataSource(CO_PARTICIPACAO_DS);
  145.  
  146. hikariConfig = new HikariConfig(additionalProperties());
  147. hikariConfig.setDataSource(dataSource);
  148. hikariConfig.setDriverClassName("com.mysql.cj.jdbc.Driver");
  149. hikariDataSource = new HikariDataSource(hikariConfig);
  150.  
  151. LOGGER.info("END");
  152. return hikariDataSource;
  153. } catch (Exception e) {
  154. LOGGER.error(e.getMessage(), e);
  155. throw new CoParticipacaoException(e);
  156. }
  157. }
Add Comment
Please, Sign In to add comment