首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring :加载多个.xml配置文件

Spring :加载多个.xml配置文件
EN

Stack Overflow用户
提问于 2013-08-03 06:53:21
回答 1查看 3.1K关注 0票数 2

我正在尝试开发一个在spring框架中加载多个配置.xml文件的程序。

这是我遇到的错误:

代码语言:javascript
复制
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'JDBCTemplateFileLog' defined in class path resource [BeansFileLog.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:
PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'dataSource' threw exception; nested exception is java.lang.IllegalArgumentException: Property 'dataSource' is required

这些是我的xml文件:

  1. Beans-All-Modules.xml <import resource="BeansJDBC.xml" /> <import resource="BeansFileLog.xml" /> <import resource="BeansCFAE.xml" />
  2. BeansJDBC.xml <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/TEST"/> <property name="username" value="root"/> <property name="password" value="password"/> </bean>
  3. BeansFileLog.xml ‘``
  4. BeansCFAE.xml <bean id="customFileAccessEvent" class="in.customfileaccessevent.CustomFileAccessEvent"> <constructor-arg index="0" type="java.lang.String"> <value>E:/HelloWorld.doc</value> </constructor-arg> </bean> <bean id="customEventHandler" class="in.customfileaccessevent.CustomFileAccessEventHandler" /> <bean id="customFileAccessEventPublisher" class="in.customfileaccessevent.CustomFileAccessEventPublisher" />

我在程序中添加了外部jar文件“MysqlConnecterJ .jar”。我还是搞不懂问题出在哪里?

MainApp.java程序如下:

公共类MainAppAllModules {

代码语言:javascript
复制
public static void main(String args[]){
    ConfigurableApplicationContext context = 
            new ClassPathXmlApplicationContext("Beans-All-Module.xml");
    //ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"BeansCFAE.xml", "BeansJDBC.xml"});

            CustomFileAccessEvent ce = (CustomFileAccessEvent) context.getBean("customFileAccessEvent");
    CustomFileAccessEventPublisher cvp = 
            (CustomFileAccessEventPublisher) context.getBean("customFileAccessEventPublisher");
    cvp.publish(ce);  
    /*ConfigurableApplicationContext context1 = 
            new ClassPathXmlApplicationContext("BeansJDBC.xml");*/  
    JDBCTemplateFileLog flogJDBCTemplate = (JDBCTemplateFileLog) context.getBean("JDBCTemplateFileLog");
    System.out.println("File Log Creation");
    flogJDBCTemplate.create("Sample", "Sample");



}

}`

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-03 06:58:30

您需要制作一个dataSource bean以供"dataSource“引用。您的xml文件导入良好。试着用本教程来做这个。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18030217

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档