我收到以下错误:运行以下代码时。我只有在 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");
尽管 bean 已经在 xml 文件中配置,但它给出了以下错误?
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>