Advertisement
Guest User

Untitled

a guest
Sep 5th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.87 KB | None | 0 0
  1. group 'SpringBootExample'
  2. version '1.0-SNAPSHOT'
  3.  
  4. apply plugin: 'java'
  5. apply plugin: 'application'
  6. apply plugin: 'eclipse'
  7. apply plugin: 'idea'
  8. apply plugin: 'org.springframework.boot'
  9.  
  10. sourceCompatibility = 1.8
  11. targetCompatibility = 1.8
  12.  
  13. mainClassName ="com.common.Application"
  14.  
  15. buildscript {
  16. repositories {
  17. mavenCentral()
  18. }
  19. dependencies {
  20. classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.6.RELEASE")
  21. }
  22. }
  23.  
  24. repositories {
  25. mavenCentral()
  26. }
  27.  
  28. // Include dependent libraries in archive.
  29. jar {
  30. manifest {
  31. attributes "Main-Class": "$mainClassName"
  32. }
  33.  
  34. from {
  35. configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
  36. }
  37. }
  38.  
  39. dependencies {
  40. testCompile group: 'junit', name: 'junit', version: '4.12'
  41.  
  42. //Spring
  43. testCompile("org.springframework.boot:spring-boot-starter-test")
  44. compile("org.springframework.boot:spring-boot-starter-web") {
  45. exclude module: "spring-boot-starter-tomcat"
  46. }
  47. compile("org.springframework.boot:spring-boot-starter-jetty")
  48. compile("org.springframework.boot:spring-boot-starter-actuator")
  49.  
  50. compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '1.4.0.RELEASE'
  51.  
  52.  
  53. //Hibernate
  54. compile group: 'org.hibernate', name: 'hibernate-core', version: '4.3.6.Final'
  55. compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '4.3.6.Final'
  56.  
  57.  
  58. //JSON
  59. compile group: 'org.json', name: 'json', version: '20090211'
  60.  
  61. //Log4j
  62. compile group: 'log4j', name: 'log4j', version: '1.2.16'
  63.  
  64.  
  65.  
  66. compile 'javax.servlet:javax.servlet-api:3.1.0'
  67. compile 'org.javassist:javassist:3.15.0-GA'
  68. compile 'commons-dbcp:commons-dbcp:1.4'
  69.  
  70. //Postgres driver
  71. compile group: 'postgresql', name: 'postgresql', version: '9.0-801.jdbc4'
  72.  
  73.  
  74. compile group: 'org.apache.tomcat.embed', name: 'tomcat-embed-jasper', version: '8.0.36'
  75. compile group: 'javax.servlet', name: 'jstl', version: '1.2'
  76. compile group: 'org.eclipse.jdt.core.compiler', name: 'ecj', version: '4.4.2'
  77.  
  78. }
  79.  
  80. package com.common.config;
  81.  
  82. import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  83. import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
  84. import org.springframework.context.annotation.Configuration;
  85. import org.springframework.web.servlet.config.annotation.EnableWebMvc;
  86.  
  87.  
  88. @Configuration
  89. public class AppMainConfig {
  90.  
  91. }
  92.  
  93. package com.common.config;
  94.  
  95. import com.common.dao.GenericDao;
  96. import com.common.dao.entity.Avatar;
  97. import com.common.dao.impl.PurchaseDao;
  98. import com.common.util.log.Log;
  99. import org.apache.commons.dbcp.BasicDataSource;
  100. import org.hibernate.SessionFactory;
  101. import org.hibernate.cfg.NamingStrategy;
  102. import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  103. import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
  104. import org.springframework.context.annotation.Bean;
  105. import org.springframework.context.annotation.Configuration;
  106. import org.springframework.context.annotation.EnableAspectJAutoProxy;
  107. import org.springframework.orm.hibernate4.HibernateTemplate;
  108. import org.springframework.orm.hibernate4.HibernateTransactionManager;
  109. import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;
  110. import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
  111. import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
  112. import org.springframework.transaction.annotation.EnableTransactionManagement;
  113.  
  114. import javax.management.InstanceAlreadyExistsException;
  115. import javax.management.MBeanRegistrationException;
  116. import javax.management.MalformedObjectNameException;
  117. import javax.management.NotCompliantMBeanException;
  118. import javax.sql.DataSource;
  119. import java.util.Arrays;
  120. import java.util.HashMap;
  121. import java.util.Map;
  122. import java.util.Properties;
  123.  
  124. @Configuration
  125. @EnableTransactionManagement
  126. @EnableAspectJAutoProxy(proxyTargetClass = true)
  127. public class HibernateConfig {
  128.  
  129.  
  130. @Bean
  131. public HibernateTemplate hibernateTemplate() {
  132. return new HibernateTemplate(sessionFactory());
  133. }
  134.  
  135. @Bean
  136. public SessionFactory sessionFactory() {
  137.  
  138. final String daoPackage = GenericDao.class.getPackage().getName();
  139.  
  140. final LocalSessionFactoryBuilder localSessionFactoryBuilder = new LocalSessionFactoryBuilder(getDataSource());
  141.  
  142. return localSessionFactoryBuilder
  143. .scanPackages(daoPackage)
  144. .buildSessionFactory();
  145. }
  146.  
  147. @Bean
  148. public DataSource getDataSource() {
  149.  
  150.  
  151. BasicDataSource dataSource = new BasicDataSource();
  152. dataSource.setDriverClassName("org.postgresql.Driver");
  153. dataSource.setUrl("jdbc:postgresql://localhost:5432/mydb");
  154. dataSource.setUsername("userName");
  155. dataSource.setPassword("");
  156.  
  157. return dataSource;
  158. }
  159.  
  160. @Bean
  161. public HibernateTransactionManager transactionManager() {
  162. return new HibernateTransactionManager(sessionFactory());
  163. }
  164.  
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement