-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
703 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,87 @@ | ||
# skeleton-ws-spring-boot | ||
# Project Skeleton for Spring Boot Web Services | ||
|
||
## Acknowledgements | ||
|
||
This is a [LEAN**STACKS**](http://www.leanstacks.com) solution. | ||
|
||
## Getting Started | ||
|
||
This is a project skeleton for a [Spring Boot](http://projects.spring.io/spring-boot/) RESTful web services application. | ||
|
||
## Languages | ||
|
||
This project is authored in Java. | ||
|
||
## Installation | ||
|
||
### Fork the Repository | ||
|
||
Fork the [Spring Boot web services skeleton project](https://github.com/mwarman/skeleton-ws-spring-boot) on GitHub. Clone the project to the host machine. | ||
|
||
### Dependencies | ||
|
||
The project requires the following dependencies be installed on the host machine: | ||
|
||
* Java Development Kit 7 or later | ||
* Apache Maven 3 or later | ||
|
||
## Running | ||
|
||
The project uses [Maven](http://maven.apache.org/) for build, package, and test workflow automation. The following Maven goals are the most commonly used. | ||
|
||
### spring-boot:run | ||
|
||
The `spring-boot:run` Maven goal performs the following workflow steps: | ||
|
||
* compiles Java classes to the /target directory | ||
* copies all resources to the /target directory | ||
* starts an embedded Apache Tomcat server | ||
|
||
To execute the `spring-boot:run` Maven goal, type the following command at a terminal prompt in the project base directory. | ||
|
||
``` | ||
mvn spring-boot:run | ||
``` | ||
|
||
Type `ctrl-C` to halt the web server. | ||
|
||
This goal is used for local machine development and functional testing. Use the `package` goal for server deployment. | ||
|
||
### package | ||
|
||
The `package` Maven goal performs the following workflow steps: | ||
|
||
* compiles Java classes to the /target directory | ||
* copies all resources to the /target directory | ||
* prepares an executable JAR file in the /target directory | ||
|
||
The `package` Maven goal is designed to prepare the application for distribution to server environments. The application and all dependencies are packaged into a single, executable JAR file. | ||
|
||
To execute the `package` goal, type the following command at a terminal prompt in the project base directory. | ||
|
||
``` | ||
mvn clean package | ||
``` | ||
|
||
The application distribution artifact is placed in the /target directory and is named using the `artifactId` and `version` from the pom.xml file. To run the JAR file use the following command: | ||
|
||
``` | ||
java -jar example-1.0.0.jar | ||
``` | ||
|
||
### test | ||
|
||
The `test` Maven goal performs the following workflow steps: | ||
|
||
* compiles Java classes to the /target directory | ||
* copies all resources to the /target directory | ||
* executes the unit test suites | ||
* produces unit test reports | ||
|
||
The `test` Maven goal is designed to allow engineers the means to run the unit test suites against the main source code. This goal may also be used on continuous integration servers such as Jenkins, etc. | ||
|
||
To execute the `test` Maven goal, type the following command at a terminal prompt in the project base directory. | ||
|
||
``` | ||
mvn clean test | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
src/main/java/com/leanstacks/ws/batch/GreetingBatchBean.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
package com.leanstacks.ws.batch; | ||
|
||
import java.util.Collection; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
|
||
import com.leanstacks.ws.model.Greeting; | ||
import com.leanstacks.ws.service.GreetingService; | ||
|
||
/** | ||
* The GreetingBatchBean contains <code>@Scheduled</code> methods operating on | ||
* Greeting entities to perform batch operations. | ||
* | ||
* @author Matt Warman | ||
*/ | ||
@Component | ||
public class GreetingBatchBean { | ||
|
||
private Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
|
||
@Autowired | ||
private GreetingService greetingService; | ||
|
||
/** | ||
* Use a cron expression to execute logic on a schedule. Expression: second | ||
* minute hour day-of-month month weekday | ||
* | ||
* @see http | ||
* ://docs.spring.io/spring/docs/current/javadoc-api/org/springframework | ||
* /scheduling/support/CronSequenceGenerator.html | ||
*/ | ||
@Scheduled( | ||
cron = "${batch.greeting.cron}") | ||
public void cronJob() { | ||
logger.info("> cronJob"); | ||
|
||
// Add scheduled logic here | ||
|
||
Collection<Greeting> greetings = greetingService.findAll(); | ||
logger.info("There are {} greetings in the data store.", | ||
greetings.size()); | ||
|
||
logger.info("< cronJob"); | ||
} | ||
|
||
/** | ||
* Execute logic beginning at fixed intervals. Use the | ||
* <code>fixedRate</code> element to indicate how frequently the method is | ||
* to be invoked. | ||
*/ | ||
@Scheduled( | ||
fixedRateString = "${batch.greeting.fixedrate}") | ||
public void fixedRateJob() { | ||
logger.info("> fixedRateJob"); | ||
|
||
// Add scheduled logic here | ||
|
||
Collection<Greeting> greetings = greetingService.findAll(); | ||
logger.info("There are {} greetings in the data store.", | ||
greetings.size()); | ||
|
||
logger.info("< fixedRateJob"); | ||
} | ||
|
||
/** | ||
* Execute logic beginning at fixed intervals with a delay after the | ||
* application starts. Use the <code>fixedRate</code> element to indicate | ||
* how frequently the method is to be invoked. Use the | ||
* <code>initialDelay</code> element to indicate how long to wait after | ||
* application startup to schedule the first execution. | ||
*/ | ||
@Scheduled( | ||
initialDelayString = "${batch.greeting.initialdelay}", | ||
fixedRateString = "${batch.greeting.fixedrate}") | ||
public void fixedRateJobWithInitialDelay() { | ||
logger.info("> fixedRateJobWithInitialDelay"); | ||
|
||
// Add scheduled logic here | ||
|
||
Collection<Greeting> greetings = greetingService.findAll(); | ||
logger.info("There are {} greetings in the data store.", | ||
greetings.size()); | ||
|
||
logger.info("< fixedRateJobWithInitialDelay"); | ||
} | ||
|
||
/** | ||
* Execute logic with a delay between the end of the last execution and the | ||
* beginning of the next. Use the <code>fixedDelay</code> element to | ||
* indicate the time to wait between executions. | ||
*/ | ||
@Scheduled( | ||
fixedDelayString = "${batch.greeting.fixeddelay}") | ||
public void fixedDelayJob() { | ||
logger.info("> fixedDelayJob"); | ||
|
||
// Add scheduled logic here | ||
|
||
Collection<Greeting> greetings = greetingService.findAll(); | ||
logger.info("There are {} greetings in the data store.", | ||
greetings.size()); | ||
|
||
logger.info("< fixedDelayJob"); | ||
} | ||
|
||
/** | ||
* Execute logic with a delay between the end of the last execution and the | ||
* beginning of the next. Use the <code>fixedDelay</code> element to | ||
* indicate the time to wait between executions. Use the | ||
* <code>initialDelay</code> element to indicate how long to wait after | ||
* application startup to schedule the first execution. | ||
*/ | ||
@Scheduled( | ||
initialDelayString = "${batch.greeting.initialdelay}", | ||
fixedDelayString = "${batch.greeting.fixeddelay}") | ||
public void fixedDelayJobWithInitialDelay() { | ||
logger.info("> fixedDelayJobWithInitialDelay"); | ||
|
||
// Add scheduled logic here | ||
|
||
Collection<Greeting> greetings = greetingService.findAll(); | ||
logger.info("There are {} greetings in the data store.", | ||
greetings.size()); | ||
|
||
logger.info("< fixedDelayJobWithInitialDelay"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.leanstacks.ws.model; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
import javax.validation.constraints.NotNull; | ||
|
||
/** | ||
* The Greeting class is an entity model object. | ||
* | ||
* @author Matt Warman | ||
*/ | ||
@Entity | ||
public class Greeting { | ||
|
||
@Id | ||
@GeneratedValue | ||
private Long id; | ||
|
||
@NotNull | ||
private String text; | ||
|
||
public Greeting() { | ||
|
||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getText() { | ||
return text; | ||
} | ||
|
||
public void setText(String text) { | ||
this.text = text; | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/leanstacks/ws/repository/GreetingRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.leanstacks.ws.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import com.leanstacks.ws.model.Greeting; | ||
|
||
@Repository | ||
public interface GreetingRepository extends JpaRepository<Greeting, Long> { | ||
|
||
} |
Oops, something went wrong.