我是春天的初学者。做一个简单的例子“Hello World”,但有一个警告。
我的pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pavlo.firstspring</groupId>
<artifactId>MavenSpringdevcolibriFirst</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>4.3.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.3.3.RELEASE</version>
</dependency>
</dependencies>
</project>
我的HelloWorld.java
package com.pavlo.firstspring; public class HelloWorld {
private String message;
public void setMessage(String message){
this.message = message;
}
public void getMessage(){
System.out.println("Your Message : " + message);
}
}
My Beans.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="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-4.3.xsd">
<bean id="helloWorld" class="com.pavlo.firstspring.HelloWorld">
<property name="message" value="Hello World!"/>
</bean>
</beans>
我的MainApp.java:
package com.pavlo.firstspring;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
public class MainApp {
public static void main(String[] args) {
ApplicationContext context =
new FileSystemXmlApplicationContext("D:/MavenSpringdevcolibriFirst/src/main/resources/Beans.xml");
HelloWorld obj = (HelloWorld) context.getBean("helloWorld");
obj.getMessage();
}
}
在控制台中:
2016年9月22日下午4:38:11 org.springframework.context.support.FileSystemXmlApplicationContext prepareRefresh INFO:刷新 org.springframework.context.support.FileSystemXmlApplicationContext@238e0d81: 启动日期[Thu Sep 22 16:38:11 EEST 2016];背景的根源 层次结构2016年9月22日下午4:38:12 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions INFO:从文件加载XML bean定义 [d:\ MavenSpringdevcolibriFirst \ SRC \主\资源\的beans.xml]
您的留言:Hello World!
错误在哪里?