1
Can someone help me with this mistake?
No qualifying bean of type [br.com.spring.JPA.Service.PostService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations:
{@org.springframework.beans.factory.annotation.Autowired(required=true)}
Postrepository:
@Repository
public interface PostRepository<P> extends JpaRepository<Post, Long> {
}
Postservice:
@Service
public class PostService {
@Autowired
PostRepository<Post> postRepository;
@Transactional
public List<Post> getAllPosts() {
return (List<Post>) postRepository.findAll();
} ...
Jpaconfig:
@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;
}
}
Postcontroller:
@Controller
public class PostController {
@Autowired
PostService bd;
...
Add the package structure of your project. Where is the main class, starting point of the application?
– Murillo Goulart