Eclipse + Spring + maven Building a RESTful Web Service ---需要添加注释
2015-03-02 22:32
513 查看
1.Eclipse --> help --> new software 安装Maven插件
url:
2.Eclipse 创建 Maven project (勾选 create a simple project)
groupId ,artifactId 为必填项,项目新建成功后对应 pom.xml 中的 <groupId >和<artifactId >中的值
3.修改pom.xml
文档查考:http://maven.apache.org/pom.html#The_Basics
添加配置文件:
<parent>
<groupId>org.springframework.boot</groupId><!--This is generally unique amongst an organization or a project-->
<artifactId>spring-boot-starter-parent</artifactId><!--The artifactId is generally the name that the project is known by-->
<version>1.2.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-release</id>
<url>https://repo.spring.io/libs-release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-release</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
4.添加实体类:
public class Greeting {
private final long id;
private final String content;
public Greeting(long id,String content){
this.id = id;
this.content = content;
}
public long getId() {
return id;
}
public String getContent() {
return content;
}
}
5.添加Controller:
@RestController
public class GreetingController {
private static final String template = "hello,%s!";
private final AtomicLong counter = new AtomicLong();
@RequestMapping("/greeting")
public Greeting greeting(@RequestParam(value="name",defaultValue="world")String name){
return new Greeting(counter.getAndIncrement(),String.format(template, name));
}
}
6.添加项目启动类:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
7.项目启动访问url :http://localhost:8080/greeting 返回结果:
url:
http://download.eclipse.org/technology/m2e/releases
2.Eclipse 创建 Maven project (勾选 create a simple project)
groupId ,artifactId 为必填项,项目新建成功后对应 pom.xml 中的 <groupId >和<artifactId >中的值
3.修改pom.xml
文档查考:http://maven.apache.org/pom.html#The_Basics
添加配置文件:
<parent>
<groupId>org.springframework.boot</groupId><!--This is generally unique amongst an organization or a project-->
<artifactId>spring-boot-starter-parent</artifactId><!--The artifactId is generally the name that the project is known by-->
<version>1.2.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-release</id>
<url>https://repo.spring.io/libs-release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-release</id>
<url>https://repo.spring.io/libs-release</url>
</pluginRepository>
</pluginRepositories>
4.添加实体类:
public class Greeting {
private final long id;
private final String content;
public Greeting(long id,String content){
this.id = id;
this.content = content;
}
public long getId() {
return id;
}
public String getContent() {
return content;
}
}
5.添加Controller:
@RestController
public class GreetingController {
private static final String template = "hello,%s!";
private final AtomicLong counter = new AtomicLong();
@RequestMapping("/greeting")
public Greeting greeting(@RequestParam(value="name",defaultValue="world")String name){
return new Greeting(counter.getAndIncrement(),String.format(template, name));
}
}
6.添加项目启动类:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
7.项目启动访问url :http://localhost:8080/greeting 返回结果:
{"id":1,"content":"hello,world!"} 测试成功:(Maven + Restful)学习阶段,暂且不加注释
相关文章推荐
- Building a RESTful Web Service Using Spring Boot In Eclipse
- Spring起步(一)Building a RESTful Web Service
- Spring Boot: Building a RESTful Web Service
- SpringBoot 之 Building a RESTful Web Service
- Spring Building a RESTful Web Service
- Eclipse安装CXF插件开发java web service 集成Spring
- 使用 Apache Wink、Eclipse 和 Maven 开发 RESTful Web 服务
- Eclipse, tomcat7.0, maven,git 构建RESTful风格的web 工程(搭建环境)
- eclipse新建maven webapp后无法添加src/main/java和src/main/test
- 关于搭建restful web service + springMVC + ibatis/hibernate的整合和XML配置意思和ssh+springMVC框架搭建
- 使用CXF与Spring集成实现RESTFul WebService
- 使用 Apache Wink、Eclipse 和 Maven 开发 RESTful Web 服务
- Eclipse Maven项目 Spring4 MVC 配置 Freemarker视图添加 templateLoaderPath 时报错
- 使用 Apache Wink、Eclipse 和 Maven 开发 RESTful Web 服务
- Eclipse安装CXF插件开发java web service 集成Spring
- Maven项目缺少eclipse自带的插件项目需要建立lib目录加上jar包,或者是已经生成有的, 然后 右键build path add libraries web app libraries
- Eclipse安装CXF插件开发java web service 集成Spring
- Spring restful web service编码乱码问题
- Spring 3 MVC Framework Based Hello World Web Application Example Using Maven, Eclipse IDE And Tomcat
- eclipse新建maven webapp后无法添加src/main/java