Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion examples/boot-more/README.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
What is more?

1. Use Jetty instead of Tomcat
2. Don't use spring boot parent
2. Use JavaSimon, demo AOP and Servlet mapping definition
49 changes: 42 additions & 7 deletions examples/boot-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@
<packaging>war</packaging>
<name>Springside :: Example :: SpringBoot WebService</name>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.1.RELEASE</version>
</parent>

<properties>
<springside.version>4.3.0-SNAPSHOT</springside.version>
<spring-boot.version>1.1.10.RELEASE</spring-boot.version>
<commons-lang3.version>3.2.1</commons-lang3.version>
<assertj.version>1.7.0</assertj.version>

<java.version>1.7</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.6</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>

<dependencies>
Expand All @@ -30,6 +28,7 @@
<artifactId>spring-boot-starter-web</artifactId>
</dependency>


<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
Expand All @@ -50,6 +49,7 @@
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>

<!-- utils -->
Expand Down Expand Up @@ -93,7 +93,42 @@
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.5</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>

<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,23 @@
* 统一定义id的entity基类.
*
* 基类统一定义id的属性名称、数据类型、列名映射及生成策略.
* Oracle需要每个Entity独立定义id的SEQUCENCE时,不继承于本类而改为实现一个Idable的接口.
* Oracle需要每个Entity独立定义id的SEQUCENCE时,不继承于本类而改为实现一个Idable的接口
*
* @author calvin
*/
// JPA 基类的标识
@MappedSuperclass
public abstract class IdEntity {

protected Long id;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Long id;
public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,36 @@
@Table(name = "ss_task")
public class Task extends IdEntity {

public String title;
public String description;
private String title;
private String description;
private User user;

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

// 基于user_id列的多对一关系定义.
@ManyToOne
@JoinColumn(name = "user_id")
public User user;
public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}

@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@Table(name = "ss_user")
public class User extends IdEntity {

public String name;
private String name;

public User() {
}
Expand All @@ -19,6 +19,14 @@ public User(Long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

@Override
public String toString() {
return ToStringBuilder.reflectionToString(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.repository.CrudRepository;
import org.springside.examples.bootservice.domain.Task;

/**
* 基于Spring Data JPA的Dao接口。
*/
public interface TaskDao extends JpaRepository<Task, Long> {
public interface TaskDao extends CrudRepository<Task, Long> {

List<Task> findByUserId(Long id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*------------------------------------------------------------------------------
* COPYRIGHT Ericsson 2014
*
* The copyright to the computer program(s) herein is the property of
* Ericsson Inc. The programs may be used and/or copied only with written
* permission from Ericsson Inc. or in accordance with the terms and
* conditions stipulated in the agreement/contract under which the
* program(s) have been supplied.
*----------------------------------------------------------------------------*/
package org.springside.examples.bootservice.rest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.metrics.CounterService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class IndexRestController {

@Autowired
private CounterService counterService;

@RequestMapping(value = "/", produces = "text/html")
public String index() {
counterService.increment("web.index");
return "<html><body>"
+ "<p>Access below management endpoint:"
+ "<ul>"
+ "<li><a href=\"http://localhost:7002/health\">http://localhost:7002/health</a></li>"
+ "<li><a href=\"http://localhost:7002/info\">http://localhost:7002/info</a></li>"
+ "<li><a href=\"http://localhost:7002/dump\">http://localhost:7002/dump</a></li>"
+ "<li><a href=\"http://localhost:7002/metrics\">http://localhost:7002/metrics</a></li>"
+ "<li><a href=\"http://localhost:7002/env\">http://localhost:7002/env</a></li>"
+ "<li>shutdown(disable by default, POST method)</li>"
+ "</ul>"
+ "<p>JMX expose as Restful by jolokia. e.g. Tomcat's MBean:"
+ "<ul>"
+ "<li><a href=\"http://localhost:7002/jolokia/read/Tomcat:type=Connector,port=8080\">http://localhost:7002/jolokia/read/Tomcat:type=Connector,port=8080</a></li>"
+ "</ul></p>" + "</body></html>";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class TaskRestController {

@RequestMapping(method = RequestMethod.GET, produces = MediaTypes.JSON_UTF_8)
public List<Task> list() {
counterService.increment("task.list");
counterService.increment("web.task.list");
return taskService.getAllTask();
}

Expand All @@ -43,28 +43,27 @@ public Task get(@PathVariable("id") Long id) {
}

@RequestMapping(method = RequestMethod.POST, consumes = MediaTypes.JSON)
public ResponseEntity<?> create(@RequestBody Task task,
UriComponentsBuilder uriBuilder) {
public ResponseEntity<?> create(@RequestBody Task task, UriComponentsBuilder uriBuilder) {
counterService.increment("task.create");
// 保存任务
taskService.saveTask(task);

// 按照Restful风格约定, 创建指向新任务的url, 也可以直接返回id或对象.
HttpHeaders headers = createLocation(uriBuilder, "/task/" + task.id);
// 按照Restful风格约定,创建指向新任务的url, 也可以直接返回id或对象.
Long id = task.getId();
HttpHeaders headers = createLocation(uriBuilder, "/task/" + id);

return new ResponseEntity(headers, HttpStatus.CREATED);
}

private HttpHeaders createLocation(UriComponentsBuilder uriBuilder,
String path) {
private HttpHeaders createLocation(UriComponentsBuilder uriBuilder, String path) {
URI uri = uriBuilder.path(path).build().toUri();
HttpHeaders headers = new HttpHeaders();
headers.setLocation(uri);
return headers;
}

@RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaTypes.JSON)
// 按Restful风格约定, 返回204状态码, 无内容, 也可以返回200状态码.
// 按Restful风格约定返回204状态码, 无内容. 也可以返回200状态码.
@ResponseStatus(HttpStatus.NO_CONTENT)
public void update(@RequestBody Task task) {
counterService.increment("task.update");
Expand Down

This file was deleted.

19 changes: 16 additions & 3 deletions examples/boot-service/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
# server settings
# server
server.port=8080
management.port=7002
spring.jackson.serialization.INDENT_OUTPUT=true
spring.datasource.sqlScriptEncoding=UTF-8

# logging
logging.file=/tmp/logs/bootservice.log

# pretty json format
http.mappers.json-pretty-print=true
http.mappers.json-sort-keys=true

# disable spring boot strange behavior
spring.main.show-banner=false
spring.jpa.hibernate.ddl-auto=none
spring.jpa.showsql=false

#disable useless endpoints
endpoints.autoconfig.enabled=false
endpoints.beans.enabled=false
endpoints.configprops.enabled=false
endpoints.mappings.enabled=false
endpoints.trace.enabled=false
#endpoints.shutdown.enabled=true

# /info endpoint
info.app.name=Spring Boot Web Service Example
info.app.version=${project.version}
5 changes: 5 additions & 0 deletions examples/boot-service/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<!-- logger name="org.springside.samples.quickservice" level="DEBUG"/-->
</configuration>
30 changes: 0 additions & 30 deletions examples/boot-service/src/main/webapp/index.html

This file was deleted.

Loading