Created
December 3, 2015 15:21
-
-
Save InfoSec812/cc38c6f91314aa95a933 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @SpringBootApplication | |
| @EnableJpaRepositories | |
| @EnableTransactionManagement | |
| @Slf4j | |
| public class Application { | |
| public static void main(String[] args) { | |
| ApplicationContext ctx = SpringApplication.run(Application.class, args); | |
| System.out.println("Let's inspect the beans provided by Spring Boot:"); | |
| String[] beanNames = ctx.getBeanDefinitionNames(); | |
| Arrays.sort(beanNames); | |
| for (String beanName : beanNames) { | |
| System.out.println(beanName); | |
| } | |
| } | |
| @Bean | |
| public DataSource dataSource() { | |
| EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder(); | |
| return builder.setType(EmbeddedDatabaseType.HSQL).build(); | |
| } | |
| @Bean | |
| public EntityManagerFactory entityManagerFactory() { | |
| HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter(); | |
| vendorAdapter.setGenerateDdl(true); | |
| LocalContainerEntityManagerFactoryBean factory = new LocalContainerEntityManagerFactoryBean(); | |
| factory.setJpaVendorAdapter(vendorAdapter); | |
| factory.setPackagesToScan("com.zanclus.data.entities"); | |
| factory.setDataSource(dataSource()); | |
| factory.afterPropertiesSet(); | |
| return factory.getObject(); | |
| } | |
| @Bean | |
| public PlatformTransactionManager transactionManager(final EntityManagerFactory emf) { | |
| final JpaTransactionManager txManager = new JpaTransactionManager(); | |
| txManager.setEntityManagerFactory(emf); | |
| return txManager; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment