No qualifying bean of type [org.wz.controller.SyncPhoneController] is defined
写了一个清洗数据的接口
项目:
spring配置:
<!-- 扫描注解 -->
<mvc:annotation-driven />
<context:component-scan base-package="org.wz" />
所有代码写完后,执行 main方法
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:*.xml");
SyncPhoneController syncPhoneController= ctx.getBean(SyncPhoneController.class);
syncPhoneController.syscPhoneBypage();
}
抛出异常
Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.wz.controller.SyncPhoneController] is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:372)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:332)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1063)
at org.wz.controller.SyncPhoneController.main(SyncPhoneController.java:47)
解决办法:
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:config/application-context.xml");
SyncPhoneController syncPhoneController= ctx.getBean(SyncPhoneController.class);
syncPhoneController.syscPhoneBypage();
}
把 "classpath:*xml" 改成"classpath:config/application-context.xml"
ok 了
一点点改变,有很大的不同。