类路径资源Config.xml中的XML文档无效

时间:2017-05-13 15:06:02

标签: java xml spring eclipse

我刚刚开始学习spring框架,但是当我尝试执行helloworld项目时,我无法看到输出,当我运行项目时,我得到这个输出,请找到下面的图像。这是我在eclipse IDE中的结构。

这是我得到的错误enter image description here

这是我编写的Config.xml和Java Code 包com.springtutorial;

public class HelloWorld {
  private String message;

  public void setMessage(String message){
     this.message=message;
  }

  public void getMessage(){
     System.out.println("Your Message:"+message);
  }
}

package com.springtutorial;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MainApp {
    public static void main(String []args){
        ApplicationContext ctx = new ClassPathXmlApplicationContext("Config.xml");

        HelloWorld hw = (HelloWorld) ctx.getBean("helloWorld");
        hw.getMessage();
    }
}

这是我的config.xml

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
    <bean id="helloWorld" class="com.springtutorial.HelloWorld">
        <property name="message" value="Hello World">
        </property>
    </bean>
</beans>

1 个答案:

答案 0 :(得分:0)

尝试以下代码: -

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
         http://www.springframework.org/schema/data/jpa
        http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">

</beans>

您可以尝试以下代码: -

ng serve --prod