| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4650 人关注过本帖
标题:使用main方法通过ClassPathXmlApplicationContext调用service接口出错
取消只看楼主 加入收藏
小萍子
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-9-14
结帖率:0
收藏
 问题点数:0 回复次数:0 
使用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)
搜索更多相关主题的帖子: software expected service public single 
2016-09-21 20:07
快速回复:使用main方法通过ClassPathXmlApplicationContext调用service接口出错
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.064559 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved