Guest User

Untitled

a guest
Jul 18th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. @Repository
  2. public interface PostRepository<P> extends JpaRepository<Post, Long> {
  3. }
  4.  
  5. @Service
  6. public class PostService {
  7.  
  8. @Autowired
  9. PostRepository<Post> postRepository;
  10.  
  11. @Transactional
  12. public List<Post> getAllPosts() {
  13. return (List<Post>) postRepository.findAll();
  14. } ...
  15.  
  16. @Configuration
  17. @EnableTransactionManagement
  18. @ComponentScan(basePackages="br.com.spring")
  19. @EnableJpaRepositories("br.com.spring.JPA.Repository")
  20. public class JPAConfig {
  21. @Bean
  22. public EntityManager entityManager(EntityManagerFactory entityManagerFactory) {
  23. return entityManagerFactory.createEntityManager();
  24. }
  25.  
  26. @Bean
  27. public EntityManagerFactory createEntityManagerFactory() {
  28. return Persistence.createEntityManagerFactory("PU");
  29. }
  30.  
  31. @Bean
  32. public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
  33. JpaTransactionManager transactionManager = new JpaTransactionManager();
  34. transactionManager.setEntityManagerFactory(emf);
  35. return transactionManager;
  36. }
  37. }
  38.  
  39. @Controller
  40. public class PostController {
  41.  
  42. @Autowired
  43. PostService bd;
  44. ...
Add Comment
Please, Sign In to add comment