@TOC
新建项目
选择Maven , 勾选Create from archetype,然后选中maven-archetype-webapp,下一步。
填写项目名和储存位置
配置Maven
默认即可,完成新建。
下载Maven文件
右下角有个小窗口,下滑点击accept,等待更新,还挺久的。。。
文件结构目录
在main目录下新建recources文件夹
右键main --> new --> directory
在将recources文件设为resource root
右键recources -->mark directory as --> Resouces Root
最后结果如下图
在main目录下新建java文件夹
和上面一样新建java文件,然后再mark directory as中选择sources root
结果如下
在src/test目录下新建spring test 包
在mark directory as中选择 Test Sources Root
效果如下
添加Spring pom依赖
最后等待依赖包下载
在recources文件夹中添加一个Spring Config
如果发现没有Spring Config , 请更换IDEA为商业版,然后重新操作.
完成新建
最后的文件结构
新建文件进行测试
在src/main/java目录下新建Test包及TestIn接口和Test类
package Test;
public interface TestIn {
void say();
}
package Test;
public class Test implements TestIn{
public void say(){
System.out.println("hello Spring");
}
}
在applicationContext.xml内增加这条语句
在src/test/java/SpringTest包内新建Spring测试类
package SpringTest;
import Test.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class SpringTest {
@org.junit.Test
public void demo(){
ApplicationContext application = new ClassPathXmlApplicationContext("applicationContext.xml");
Test test = (Test)application.getBean("TestIn");
test.say();
}
}
之后开始测试
这样就成功的运行一个spring程序。