I have an error in Spring MVC.
Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [service.NewsServiceImpl] is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:373)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:333)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1088)
at controller.Testing.main(Testing.java:24)
@Repository
public class NewsDAImpl implements NewsDA {
@PersistenceContext
private EntityManager context;
@Override
public News ... Some Other Codes
@Service
@Transactional
public class NewsServiceImpl implements NewsService{
@Autowired
private NewsDAImpl newsDa;
@Override
public News ... Some Other Codes
ApplicationContext context = new AnnotationConfigApplicationContext(ProjectConfig.class);
NewsServiceImpl service = context.getBean(NewsServiceImpl.class);
Change
NewsServiceImpl service = context.getBean(NewsServiceImpl.class);
to
NewsService service = context.getBean(NewsService.class);
You have NewServiceImpl
annotated with @Transactional
, so by default spring will create a proxy which of course implements NewsService
instead of NewsServiceImpl
.