使用main方法通过ClassPathXmlApplicationContext调用service接口出错
我不通过controller层调用service接口,而是使用main方法通过ClassPathXmlApplicationContext调用service接口,会报No unique bean of type [com.ultrapower.demo.service.impl.AppServiceImpl] is defined: expected single bean but found 0:
main方法代码如下:
public static void main(String[] args) {
String path="D:\\software\\apache-tomcat-6.0.45\\webapps\\QuartzTest\\WEB-INF\\conf\\beans\\*.xml";
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("file:"+path);
IAppService iAppService = applicationContext.getBean(AppServiceImpl.class);
String appStr = iAppService.getApp();
System.out.println(appStr);
}
dao的配置
<bean id="iAppDao" class="com.ultrapower.demo.dao.impl.AppDaoImpl" parent="baseDao">
</bean>
service的配置:
<bean id="iAppService" class="com.ultrapower.demo.service.impl.AppServiceImpl"
parent="baseService" >
<property name="iAppDao" ref="iAppDao" />
</bean>
报错:log4j:WARN No appenders could be found for logger (org.springframework.context.support.ClassPathXmlApplicationContext).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [com.ultrapower.demo.service.impl.AppServiceImpl] is defined: expected single bean but found 0:
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBean(DefaultListableBeanFactory.java:269)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1083)
at test.springtest.SpringTest1.main(SpringTest1.java:21)