No Qualifying bean of type [br.com.spring.JPA.Service.Postservice] found for dependency

Asked

Viewed 201 times

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;
...
  • 1

    Add the package structure of your project. Where is the main class, starting point of the application?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.