Intellij IDEA Ultimate Spring Hello World
写在前面
IDEA Ultimate Spring 开发 hello world!
参考:
开始
创建一个项目

点击Create New Project选项。
Spring MVC 选项

Spring -> Project SDK设置你的 jdk -> Spring MVC -> 如果已经下载了 Spring 压缩包,可选择Use library,建议勾选Download自动下载 -> Next完成初始配置
自定义项目位置

选择你的项目位置。
工程目录

在项目名称下(我的项目名称为Spring)的 src 目录中创建文件: 接口文件Demo.java、接口实现文件Main.java、Spring 创建对象实例的applicationContext.xml文件、测试文件Test.java。
Hello World
创建接口

public interface Demo {
public void say();
}
实现接口

public class Main implements Demo {
@Override
public void say() {
System.out.println("hello world");
}
}
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.xsd">
<bean id="Demo" class="Main"></bean>
</beans>
测试程序

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class Test {
public static void main(String[] args) {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
Demo demo = (Demo)applicationContext.getBean("Demo");
demo.say();
}
}
hello world

comment:
- Valine
- LiveRe
- ChangYan