Guest User

Untitled

a guest
Oct 26th, 2017
430
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.23 KB | None | 0 0
  1. . ____ _ __ _ _
  2. /\ / ___'_ __ _ _(_)_ __ __ _
  3. ( ( )___ | '_ | '_| | '_ / _` |
  4. \/ ___)| |_)| | | | | || (_| | ) ) ) )
  5. ' |____| .__|_| |_|_| |___, | / / / /
  6. =========|_|==============|___/=/_/_/_/
  7. :: Spring Boot :: (v1.5.8.RELEASE)
  8.  
  9. 2017-10-26 10:04:15.198 INFO 2936 --- [ main] .g.a.s.SpringBootPostgreApplicationTests : Starting SpringBootPostgreApplicationTests on DESKTOP-N1P2FPC with PID 2936 (started by Nyansus in H:╤Г╤З╨╡╨▒╨░ ╨╜╨░ Hjava-spring-bootspring-boot-postgre)
  10. 2017-10-26 10:04:15.200 INFO 2936 --- [ main] .g.a.s.SpringBootPostgreApplicationTests : No active profile set, falling back to default profiles: default
  11. 2017-10-26 10:04:15.240 INFO 2936 --- [ main] o.s.w.c.s.GenericWebApplicationContext : Refreshing org.springframework.web.context.support.GenericWebApplicationContext@328cf0e1: startup date [Thu Oct 26 10:04:15 MSK 2017]; root of context hierarchy
  12. WARNING: An illegal reflective access operation has occurred
  13. SUREFIRE-859: WARNING: Illegal reflective access by org.springframework.cglib.core.ReflectUtils$1 (file:/C:/Users/Nyansus/.m2/repository/org/springframework/spring-core/4.3.12.RELEASE/spring-core-4.3.12.RELEASE.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
  14. WARNING: Please consider reporting this to the maintainers of org.springframework.cglib.core.ReflectUtils$1
  15. WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
  16. WARNING: All illegal access operations will be denied in a future release
  17. 2017-10-26 10:04:16.512 INFO 2936 --- [g-Init-Reporter] com.mchange.v2.log.MLog : MLog clients using slf4j logging.
  18. 2017-10-26 10:04:16.610 INFO 2936 --- [ main] com.mchange.v2.c3p0.C3P0Registry : Initializing c3p0-0.9.5.2 [built 08-December-2015 22:06:04 -0800; debug? true; trace: 10]
  19. 2017-10-26 10:04:16.662 WARN 2936 --- [ main] com.mchange.v2.c3p0.cfg.C3P0Config : named-config with name 'configName' does not exist. Using default-config.
  20. 2017-10-26 10:04:16.663 WARN 2936 --- [ main] com.mchange.v2.c3p0.cfg.C3P0Config : named-config with name 'configName' does not exist. Using default-config extensions.
  21. 2017-10-26 10:04:16.930 WARN 2936 --- [ main] o.s.w.c.s.GenericWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'userDaoImpl'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDao': Unsatisfied dependency expressed through field 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [io/github/aaa4/springbootpostgre/configuration/DatabaseConfig.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
  22. 2017-10-26 10:04:16.942 INFO 2936 --- [ main] utoConfigurationReportLoggingInitializer :
  23.  
  24. Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
  25. 2017-10-26 10:04:16.955 ERROR 2936 --- [ main] o.s.boot.SpringApplication : Application startup failed
  26.  
  27. org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'userDaoImpl'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDao': Unsatisfied dependency expressed through field 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [io/github/aaa4/springbootpostgre/configuration/DatabaseConfig.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
  28. at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
  29. at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
  30. at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
  31. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
  32. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
  33. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
  34. at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
  35. at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
  36. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
  37. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
  38. at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
  39.  
  40. # Thymeleaf
  41. spring.thymeleaf.cache: false
  42.  
  43. # Database
  44. db.driver:org.postgresql.Driver
  45. db.url:jdbc:postgresql://localhost:5432/spring-database
  46. db.username:postgres
  47. db.password:myPass
  48.  
  49.  
  50. # Hibernate
  51. hibernate.dialect: org.hibernate.dialect.PostgreSQLDialect
  52. hibernate.show_sql: true
  53. hibernate.hbm2ddl.auto: create
  54. entitymanager.packagesToScan: io.github.aaa4.springbootpostgre.model
  55.  
  56. # c3p0 pooling
  57. hibernate.c3p0.max_size=20
  58. hibernate.c3p0.min_size=5
  59. hibernate.c3p0.idle_test_period=600
  60.  
  61. # Logging
  62. logging.file=application.log
  63.  
  64. import com.mchange.v2.c3p0.ComboPooledDataSource;
  65. import org.springframework.beans.factory.annotation.Value;
  66. import org.springframework.context.annotation.Bean;
  67. import org.springframework.context.annotation.Configuration;
  68. import org.springframework.orm.hibernate5.HibernateTransactionManager;
  69. import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
  70. import org.springframework.transaction.annotation.EnableTransactionManagement;
  71.  
  72. import java.beans.PropertyVetoException;
  73. import java.util.Properties;
  74.  
  75. @Configuration
  76. @EnableTransactionManagement
  77. public class DatabaseConfig {
  78.  
  79. @Value("${db.driver}")
  80. private String DB_DRIVER;
  81.  
  82. @Value("${db.password}")
  83. private String DB_PASSWORD;
  84.  
  85. @Value("${db.url}")
  86. private String DB_URL;
  87.  
  88. @Value("${db.username}")
  89. private String DB_USERNAME;
  90.  
  91. @Value("${hibernate.dialect}")
  92. private String HIBERNATE_DIALECT;
  93.  
  94. @Value("${hibernate.show_sql}")
  95. private String HIBERNATE_SHOW_SQL;
  96.  
  97. @Value("${hibernate.hbm2ddl.auto}")
  98. private String HIBERNATE_HBM2DDL_AUTO;
  99.  
  100. @Value("${entitymanager.packagesToScan}")
  101. private String ENTITYMANAGER_PACKAGES_TO_SCAN;
  102.  
  103. @Value("${hibernate.c3p0.max_size}")
  104. private String CONN_POOL_MAX_SIZE;
  105.  
  106. @Value("${hibernate.c3p0.min_size}")
  107. private String CONN_POOL_MIN_SIZE;
  108.  
  109. @Value("${hibernate.c3p0.idle_test_period}")
  110. private String CONN_POOL_IDLE_PERIOD;
  111.  
  112.  
  113. @Bean
  114. public ComboPooledDataSource dataSource() {
  115. ComboPooledDataSource dataSource = new ComboPooledDataSource("configName");
  116. try {
  117. dataSource.setDriverClass(DB_DRIVER);
  118. } catch (PropertyVetoException pve){
  119. System.out.println("Cannot load datasource driver (" + DB_DRIVER +") : " + pve.getMessage());
  120. return null;
  121. }
  122. dataSource.setJdbcUrl(DB_URL);
  123. dataSource.setUser(DB_USERNAME);
  124. dataSource.setPassword(DB_PASSWORD);
  125. dataSource.setMinPoolSize(Integer.parseInt(CONN_POOL_MIN_SIZE));
  126. dataSource.setMaxPoolSize(Integer.parseInt(CONN_POOL_MAX_SIZE));
  127. dataSource.setMaxIdleTime(Integer.parseInt(CONN_POOL_IDLE_PERIOD));
  128.  
  129. return dataSource;
  130. }
  131.  
  132. @Bean
  133. public LocalSessionFactoryBean sessionFactory() {
  134. LocalSessionFactoryBean sessionFactoryBean = new LocalSessionFactoryBean();
  135. sessionFactoryBean.setDataSource(dataSource());
  136. sessionFactoryBean.setPackagesToScan(ENTITYMANAGER_PACKAGES_TO_SCAN);
  137. Properties hibernateProperties = new Properties();
  138. hibernateProperties.put("hibernate.dialect", HIBERNATE_DIALECT);
  139. hibernateProperties.put("hibernate.show_sql", HIBERNATE_SHOW_SQL);
  140. hibernateProperties.put("hibernate.hbm2ddl.auto", HIBERNATE_HBM2DDL_AUTO);
  141. sessionFactoryBean.setHibernateProperties(hibernateProperties);
  142.  
  143. return sessionFactoryBean;
  144. }
  145.  
  146. @Bean
  147. public HibernateTransactionManager transactionManager() {
  148. HibernateTransactionManager transactionManager =
  149. new HibernateTransactionManager();
  150. transactionManager.setSessionFactory(sessionFactory().getObject());
  151. return transactionManager;
  152. }
  153. }
  154.  
  155. import javax.persistence.*;
  156. import javax.validation.constraints.NotNull;
  157.  
  158. @Entity
  159. @Table(name = "users")
  160.  
  161. public class User {
  162.  
  163. @Id
  164. @GeneratedValue(strategy = GenerationType.AUTO)
  165. private long id;
  166.  
  167. @NotNull
  168. private String name;
  169.  
  170. public User(String name) {
  171. this.name = name;
  172. }
  173.  
  174. public User() {
  175. }
  176.  
  177. public long getId() {
  178. return id;
  179. }
  180.  
  181. public void setId(long id) {
  182. this.id = id;
  183. }
  184.  
  185. public String getName() {
  186. return name;
  187. }
  188.  
  189. public void setName(String name) {
  190. this.name = name;
  191. }
  192. }
  193.  
  194. import org.hibernate.Session;
  195. import org.hibernate.SessionFactory;
  196. import org.springframework.beans.factory.annotation.Autowired;
  197. import org.springframework.stereotype.Repository;
  198.  
  199. import javax.transaction.Transactional;
  200.  
  201. @Repository
  202. @Transactional
  203. public class UserDao {
  204.  
  205. @Autowired
  206. private SessionFactory sessionFactory;
  207.  
  208. private Session getSession() {
  209. return sessionFactory.getCurrentSession();
  210. }
  211.  
  212. public void save(User user) {
  213. getSession().save(user);
  214. }
  215. }
  216.  
  217. import org.springframework.boot.SpringApplication;
  218. import org.springframework.boot.autoconfigure.SpringBootApplication;
  219.  
  220. @SpringBootApplication(scanBasePackages = "io.github.aaa4.springbootpostgre")
  221. public class SpringBootPostgreApplication {
  222.  
  223. public static void main(String[] args) {
  224. SpringApplication.run(SpringBootPostgreApplication.class, args);
  225. }
  226. }
Add Comment
Please, Sign In to add comment