hossein badrnezhad hossein badrnezhad - 2 months ago 29
Java Question

No qualifying bean of type [service.NewsServiceImpl] is defined

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)

NewsDAImpl Code is :

public class NewsDAImpl implements NewsDA {

private EntityManager context;

public News ... Some Other Codes

My NewsServiceImpl class :

public class NewsServiceImpl implements NewsService{

private NewsDAImpl newsDa;

public News ... Some Other Codes

I write controller that has static void main, just for testing.
in that i wrote this :

ApplicationContext context = new AnnotationConfigApplicationContext(ProjectConfig.class);

then i just get news service with getBean method :

NewsServiceImpl service = context.getBean(NewsServiceImpl.class);

Answer Source


NewsServiceImpl service = context.getBean(NewsServiceImpl.class);


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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download