org.springframework.beans.factory.BeanDefinitionStoreException:

时间:2013-10-21 19:13:01

标签: java xml spring maven

我收到以下错误:运行以下代码时。我只在src / main / resources文件夹中有xml文件(report-context.xml)。不知道为什么它不起作用?这是maven项目。

public static void main(String[] args) {
        int execResult = -1;
        ApplicationContext appCont = new ClassPathXmlApplicationContext(
                "classpath:/report-context.xml");
        Application appBean = (Application) appCont.getBean("abcLauncher");
        if (appBean != null) {
            appBean.run();
            execResult = appBean.resultCode();
        }
        System.exit(execResult);

    }

错误:

org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML
document from class path resource [report-context.xml]; 
nested exception is  java.io.FileNotFoundException: class path resource [beans xml file   
name]cannot be opened because it does not exist

如果我将代码行更改为:

ApplicationContext appCont = new ClassPathXmlApplicationContext(
                "classpath*:/report-context.xml");

虽然已经在xml文件中配置了bean,但它给出了以下错误?

Exception in thread "main"
org.springframework.beans.factory.NoSuchBeanDefinitionException: 
No bean named 'abcLauncher' is defined

赞赏对此的任何帮助

- 添加我的xml文件的内容部分

<bean id="analystMeterDataServices" class="com.abc.pg.analystmeter.service.AnalystMeterDataServicesImpl">
        <property name="messageSender" ref="messageSender" />
        <property name="analystMeterDao" ref="analystMeterDao" />
        <property name="dataFileName"
            value="${data.dir}${data.smselector.paramsfilename}" />
        <property name="lastRunDateformat" value="${data.lastrundateformat}" /> 
    </bean>

    <bean id="abcLauncher" class="com.abc.pg.analystmeter.AnalystMeterLauncher">
        <property name="appSelectorDataServices" ref="analystMeterDataServices" />
    </bean>

0 个答案:

没有答案