搭建 spring 项目
参考原文:http://blog.csdn.net/binyao02123202/article/details/20387595
1.新建maven web 工程
2.编辑pom.xml添加依赖
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.0.2.RELEASE</version>
</dependency> <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.0.2.RELEASE</version>
</dependency>
3.配置spring监听器
编辑web.xml添加监听器
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app>
<display-name>Archetype Created Web Application</display-name> <!-- 设置Spring容器加载所有的配置文件的路径 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext.xml</param-value>
</context-param> <!-- 加载Spring容器配置,Spring监听器 -->
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
</web-app>
4. applicationContext.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"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd "> <bean id="person" class="com.yun.entity.Person">
<property name="name" value="张三"></property>
<property name="age" value="33"></property>
</bean> <bean id="helloWorld" class="com.yun.util.test.impl.IHelloWorldImpl">
<property name="person" ref="person"></property>
</bean> </beans>
5.编写测试类
package com.yun.entity;
public class Person {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
接口 IHelloWorld
package com.yun.util.test;
public interface IHelloWorld {
String sayHello();
}
接口实现 IHelloWorldImpl
package com.yun.util.test.impl; import com.yun.entity.Person;
import com.yun.util.test.IHelloWorld; public class IHelloWorldImpl implements IHelloWorld{ private Person person; public String sayHello() {
return "hello world!"+person.getName()+",i am "+person.getAge();
} public Person getPerson() {
return person;
} public void setPerson(Person person) {
this.person = person;
} }
测试类 JunitTest
package com.yun.test; import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; import com.yun.util.test.IHelloWorld; public class JunitTest { @Test
public void test(){
System.out.println("......................");
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
IHelloWorld helloWorld = (IHelloWorld)context.getBean("helloWorld");
System.out.println(helloWorld.sayHello());
}
}
运行结果

6.工程中应用了 junit 如下添加junit
选中工程右键-->Properties-->Java Build Path-->add Library-->JUnit-->next
7.如果想透彻理解,请参考博文开头的参考文章。
工程将在百度云盘中给出。
百度云: http://pan.baidu.com/s/1pLvvxQb
搭建 spring 项目的更多相关文章
- IDEA使用maven搭建spring项目
spring框架 Spring框架是由于软件开发的复杂性而创建的.Spring使用的是基本的JavaBean来完成以前只可能由EJB完成的事情.然而,Spring的用途不仅仅限于服务器端的开发.从简单 ...
- 搭建spring项目,无法创建RequestMappingHandlerMapping异常
异常详情: Error creating bean with name 'org.springframework.web.servlet.mvc.method.annotation.RequestMa ...
- 使用java配置来构建spring项目
java配置是Spring4.x推荐的配置方式,可以完全代替xml配置,java配置是通过@Configuration和@Bean来实现的.@Configuration声明当前类是一个配置类,相当于S ...
- 搭建spring mvc项目
在之前搭建maven项目这篇的基础上继续集成,引入spring mvc支持 一.添加jar包引用 修改pom.xml文件,加入:(其他关联的jar包maven会自动引用) <!-- 项目属性 - ...
- Spring MVC 项目搭建 -1- 创建项目
Spring MVC 项目搭建 -1- 创建项目 1.创建 Dynamic Web project (SpringDemo),添加相关jar包 2.创建一个简单的controller类 package ...
- 使用IDEA搭建Spring Boot入门项目
简介 Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配置 ...
- Spring Boot入门-快速搭建web项目
Spring Boot 概述: Spring Boot makes it easy to create stand-alone, production-grade Spring based Appli ...
- maven 聚合工程 用spring boot 搭建 spring cloud 微服务 模块式开发项目
项目的简单介绍: 项目采用maven聚合工程 用spring boot 搭建 spring cloud的微服务 模块式开发 项目的截图: 搭建开始: 能上图 我少打字 1.首先搭建maven的聚合工程 ...
- Spring Boot搭建Web项目常用功能
搭建WEB项目过程中,哪些点需要注意: 1.技术选型: 前端:freemarker.vue 后端:spring boot.spring mvc 2.如何包装返回统一结构结果数据? 首先要弄清楚为什么要 ...
随机推荐
- dp入门 专题记录 2017-7-26
POJ3176-Cow Bowling 题目大意:现有n行数,以金字塔的形式排列,即第一行一个数字,第二行2个数字,依次类推,现在需要找一条从第一层到第n层的路线,使得该路线上的所有点的权值和最大 思 ...
- CSS3 动画的一些属性
定义式 @keyframes 动画名称{ from{ } to{ } } 调用式 动画类似函数,只定义不调用是没效果的,所以要配合调用式使用. animation: 动画名称 动画时间 延时 时间曲线 ...
- Spring security框架原理
转自: http://www.blogjava.net/youxia/archive/2008/12/07/244883.html 在SpringSide 3的官方文档中,说安全框架使用的是Spri ...
- 【译】Asp.net core应用在 Kubernetes上内存使用率过高问题分析
原文:https://blog.markvincze.com/troubleshooting-high-memory-usage-with-asp-net-core-on-kubernetes/ ps ...
- 【转】<c:forEach varStatus="status">中 varStatus的属性简介 及应用
转载原因:在做页面的时候,需要在页面中判断循环了第几次和一共循环了多少次,在网上搜集的时候,看到这篇帖子,觉得太全面了,于是转载了.... varStatus是<c:forEach>jst ...
- 下列java代码中的变量a、b、c分别在内存的______存储区存放。
class A{ private String a = "aa"; public boolean methodB(){ String b = "sb"; fin ...
- hdu 3579 Hello Kiki 不互质的中国剩余定理
Hello Kiki Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Probl ...
- python 操作浏览器打开指定网页
#! /usr/bin/env python # encoding=utf8 import webbrowser import time webbrowser.open("http://ww ...
- zlib__ZC
官网:http://www.zlib.net/ ,所有版本下载:http://www.zlib.net/fossils/ ZC: 我下载的是 zlib-1.2.3.tar.gz 和 zlib-1.2. ...
- Cglib方法实现动态代理
除了使用JDK方式产生动态代理外,Java还给我们提供了另外一种产生动态代理的方法,那就是使用cglib. cglib是这样实现动态代理的: · ①.针对类来实现代理 · ②对指定目标类产生一个子类 ...