Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- . ____ _ __ _ _
- /\ / ___'_ __ _ _(_)_ __ __ _
- ( ( )___ | '_ | '_| | '_ / _` |
- \/ ___)| |_)| | | | | || (_| | ) ) ) )
- ' |____| .__|_| |_|_| |___, | / / / /
- =========|_|==============|___/=/_/_/_/
- :: Spring Boot :: (v1.5.8.RELEASE)
- 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)
- 2017-10-26 10:04:15.200 INFO 2936 --- [ main] .g.a.s.SpringBootPostgreApplicationTests : No active profile set, falling back to default profiles: default
- 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
- WARNING: An illegal reflective access operation has occurred
- 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)
- WARNING: Please consider reporting this to the maintainers of org.springframework.cglib.core.ReflectUtils$1
- WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
- WARNING: All illegal access operations will be denied in a future release
- 2017-10-26 10:04:16.512 INFO 2936 --- [g-Init-Reporter] com.mchange.v2.log.MLog : MLog clients using slf4j logging.
- 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]
- 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.
- 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.
- 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
- 2017-10-26 10:04:16.942 INFO 2936 --- [ main] utoConfigurationReportLoggingInitializer :
- Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
- 2017-10-26 10:04:16.955 ERROR 2936 --- [ main] o.s.boot.SpringApplication : Application startup failed
- 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
- at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
- at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
- at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:366) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1264) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:553) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
- at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
- at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
- at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
- at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
- at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761) ~[spring-beans-4.3.12.RELEASE.jar:4.3.12.RELEASE]
- # Thymeleaf
- spring.thymeleaf.cache: false
- # Database
- db.driver:org.postgresql.Driver
- db.url:jdbc:postgresql://localhost:5432/spring-database
- db.username:postgres
- db.password:myPass
- # Hibernate
- hibernate.dialect: org.hibernate.dialect.PostgreSQLDialect
- hibernate.show_sql: true
- hibernate.hbm2ddl.auto: create
- entitymanager.packagesToScan: io.github.aaa4.springbootpostgre.model
- # c3p0 pooling
- hibernate.c3p0.max_size=20
- hibernate.c3p0.min_size=5
- hibernate.c3p0.idle_test_period=600
- # Logging
- logging.file=application.log
- import com.mchange.v2.c3p0.ComboPooledDataSource;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.context.annotation.Bean;
- import org.springframework.context.annotation.Configuration;
- import org.springframework.orm.hibernate5.HibernateTransactionManager;
- import org.springframework.orm.hibernate5.LocalSessionFactoryBean;
- import org.springframework.transaction.annotation.EnableTransactionManagement;
- import java.beans.PropertyVetoException;
- import java.util.Properties;
- @Configuration
- @EnableTransactionManagement
- public class DatabaseConfig {
- @Value("${db.driver}")
- private String DB_DRIVER;
- @Value("${db.password}")
- private String DB_PASSWORD;
- @Value("${db.url}")
- private String DB_URL;
- @Value("${db.username}")
- private String DB_USERNAME;
- @Value("${hibernate.dialect}")
- private String HIBERNATE_DIALECT;
- @Value("${hibernate.show_sql}")
- private String HIBERNATE_SHOW_SQL;
- @Value("${hibernate.hbm2ddl.auto}")
- private String HIBERNATE_HBM2DDL_AUTO;
- @Value("${entitymanager.packagesToScan}")
- private String ENTITYMANAGER_PACKAGES_TO_SCAN;
- @Value("${hibernate.c3p0.max_size}")
- private String CONN_POOL_MAX_SIZE;
- @Value("${hibernate.c3p0.min_size}")
- private String CONN_POOL_MIN_SIZE;
- @Value("${hibernate.c3p0.idle_test_period}")
- private String CONN_POOL_IDLE_PERIOD;
- @Bean
- public ComboPooledDataSource dataSource() {
- ComboPooledDataSource dataSource = new ComboPooledDataSource("configName");
- try {
- dataSource.setDriverClass(DB_DRIVER);
- } catch (PropertyVetoException pve){
- System.out.println("Cannot load datasource driver (" + DB_DRIVER +") : " + pve.getMessage());
- return null;
- }
- dataSource.setJdbcUrl(DB_URL);
- dataSource.setUser(DB_USERNAME);
- dataSource.setPassword(DB_PASSWORD);
- dataSource.setMinPoolSize(Integer.parseInt(CONN_POOL_MIN_SIZE));
- dataSource.setMaxPoolSize(Integer.parseInt(CONN_POOL_MAX_SIZE));
- dataSource.setMaxIdleTime(Integer.parseInt(CONN_POOL_IDLE_PERIOD));
- return dataSource;
- }
- @Bean
- public LocalSessionFactoryBean sessionFactory() {
- LocalSessionFactoryBean sessionFactoryBean = new LocalSessionFactoryBean();
- sessionFactoryBean.setDataSource(dataSource());
- sessionFactoryBean.setPackagesToScan(ENTITYMANAGER_PACKAGES_TO_SCAN);
- Properties hibernateProperties = new Properties();
- hibernateProperties.put("hibernate.dialect", HIBERNATE_DIALECT);
- hibernateProperties.put("hibernate.show_sql", HIBERNATE_SHOW_SQL);
- hibernateProperties.put("hibernate.hbm2ddl.auto", HIBERNATE_HBM2DDL_AUTO);
- sessionFactoryBean.setHibernateProperties(hibernateProperties);
- return sessionFactoryBean;
- }
- @Bean
- public HibernateTransactionManager transactionManager() {
- HibernateTransactionManager transactionManager =
- new HibernateTransactionManager();
- transactionManager.setSessionFactory(sessionFactory().getObject());
- return transactionManager;
- }
- }
- import javax.persistence.*;
- import javax.validation.constraints.NotNull;
- @Entity
- @Table(name = "users")
- public class User {
- @Id
- @GeneratedValue(strategy = GenerationType.AUTO)
- private long id;
- @NotNull
- private String name;
- public User(String name) {
- this.name = name;
- }
- public User() {
- }
- public long getId() {
- return id;
- }
- public void setId(long id) {
- this.id = id;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- }
- import org.hibernate.Session;
- import org.hibernate.SessionFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Repository;
- import javax.transaction.Transactional;
- @Repository
- @Transactional
- public class UserDao {
- @Autowired
- private SessionFactory sessionFactory;
- private Session getSession() {
- return sessionFactory.getCurrentSession();
- }
- public void save(User user) {
- getSession().save(user);
- }
- }
- import org.springframework.boot.SpringApplication;
- import org.springframework.boot.autoconfigure.SpringBootApplication;
- @SpringBootApplication(scanBasePackages = "io.github.aaa4.springbootpostgre")
- public class SpringBootPostgreApplication {
- public static void main(String[] args) {
- SpringApplication.run(SpringBootPostgreApplication.class, args);
- }
- }
Add Comment
Please, Sign In to add comment