Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Repository
- public interface PostRepository<P> extends JpaRepository<Post, Long> {
- }
- @Service
- public class PostService {
- @Autowired
- PostRepository<Post> postRepository;
- @Transactional
- public List<Post> getAllPosts() {
- return (List<Post>) postRepository.findAll();
- } ...
- @Configuration
- @EnableTransactionManagement
- @ComponentScan(basePackages="br.com.spring")
- @EnableJpaRepositories("br.com.spring.JPA.Repository")
- public class JPAConfig {
- @Bean
- public EntityManager entityManager(EntityManagerFactory entityManagerFactory) {
- return entityManagerFactory.createEntityManager();
- }
- @Bean
- public EntityManagerFactory createEntityManagerFactory() {
- return Persistence.createEntityManagerFactory("PU");
- }
- @Bean
- public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
- JpaTransactionManager transactionManager = new JpaTransactionManager();
- transactionManager.setEntityManagerFactory(emf);
- return transactionManager;
- }
- }
- @Controller
- public class PostController {
- @Autowired
- PostService bd;
- ...
Add Comment
Please, Sign In to add comment