Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created mullti-modile Spring Boot Angular 5 starter project
- Loading branch information
0 parents
commit 33fd79f
Showing
43 changed files
with
7,779 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# See http://help.github.com/ignore-files/ for more about ignoring files. | ||
|
||
# compiled output | ||
dist | ||
tmp | ||
out-tsc | ||
bin/ | ||
# dependencies | ||
node_modules/ | ||
node/ | ||
target/ | ||
|
||
# IDEs and editors | ||
/.idea | ||
.project | ||
.classpath | ||
.c9/ | ||
*.launch | ||
.settings/ | ||
*.sublime-workspace | ||
|
||
# IDE - VSCode | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json | ||
|
||
# misc | ||
.sass-cache | ||
connect.lock | ||
coverage | ||
libpeerconnection.log | ||
npm-debug.log | ||
testem.log | ||
/typings | ||
|
||
# e2e | ||
e2e/*.js | ||
e2e/*.map | ||
|
||
# System Files | ||
.DS_Store | ||
Thumbs.db | ||
*.iml | ||
ui-src/ |
Binary file not shown.
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 @@ | ||
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.2/apache-maven-3.5.2-bin.zip |
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,70 @@ | ||
spring-boot-maven-angular-starter | ||
----- | ||
|
||
This is a multi-module Spring Boot Angular Maven starter app with good defaults. | ||
The frontend Angular app is built using [angular-cli](https://cli.angular.io/). The project packages Angular application code as a [WebJar](https://www.webjars.org/). This project is geared towards building monolithic applications. | ||
|
||
This project provides productive setup for building Spring Boot React applications. The application is divided into two Maven modules: | ||
|
||
1. `backend`: This contains Java code of the application. | ||
2. `frontend`: This contains source code for the Angular based frontend. | ||
|
||
This project uses following versions: | ||
|
||
1. Spring Boot 1.5.8 | ||
2. Angular 5.0.0 | ||
3. Node v8.9.0 | ||
4. Yarn v1.3.2 | ||
|
||
## Running the full application | ||
|
||
You can build the package as a single artifact by running the `./mvnw clean install`. | ||
Next, you can run the application by executing: | ||
|
||
```bash | ||
$ java -jar backend/target/ngboot-app.jar | ||
``` | ||
|
||
The application will be accessible at `http://localhost:8080`. | ||
|
||
## Features | ||
|
||
This starter comes bundled with the following features: | ||
|
||
1. Multi module Maven project: A multi module project to modularize backend and frontend code separately. | ||
2. Maven wrapper: So, you don't need to install Maven on your machine. | ||
3. Checkstyle: Enforce sane coding standard guidelines. | ||
4. ErrorProne: Find errors in your code. | ||
5. Frontend packaged as a WebJar. | ||
6. CORS enabled: A global configuration is added to enable CORS so that frontend can work seamlessly with backend during development. | ||
7. REST API base path: Sets the base REST API path to `/api`. You can configure it by changing `rest.api.base.path` property. | ||
8. Maven release plugin | ||
|
||
## Running the backend for development mode | ||
|
||
There are multiple ways to run the backend. For development, you can use your favorite IDE and run the | ||
`com.example.app.Application`. As soon as your code compiles, Spring Boot DevTools will reload the code. | ||
|
||
You can also run the application using Maven. | ||
|
||
```bash | ||
$ cd backend | ||
$ ../mvnw spring-boot:run | ||
``` | ||
|
||
## Running the frontend for development mode | ||
|
||
Make sure to install [yarn on your development machine](https://yarnpkg.com/en/docs/install). | ||
|
||
To install all the required binaries for your project, you can run following command. | ||
|
||
``` | ||
$ cd frontend | ||
$ ../mvnw frontend:install-node-and-yarn frontend:yarn | ||
``` | ||
|
||
Once the above command finishes, you can start the frontend using the `yarn start` command. | ||
|
||
## Hot reloading | ||
|
||
Both the frontend and backend support hot reloading. |
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,79 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>spring-boot-angular-starter</artifactId> | ||
<groupId>com.shekhargulati.starters.ngboot</groupId> | ||
<version>0.1.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>backend</artifactId> | ||
|
||
<properties> | ||
<main.basedir>${project.parent.basedir}</main.basedir> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.shekhargulati.starters.ngboot</groupId> | ||
<artifactId>frontend</artifactId> | ||
<version>${project.parent.version}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-actuator</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-actuator-docs</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-thymeleaf</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-devtools</artifactId> | ||
<scope>runtime</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<finalName>ngboot-app</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-checkstyle-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<phase>verify</phase> | ||
<goals> | ||
<goal>checkstyle</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
66 changes: 66 additions & 0 deletions
66
backend/src/main/java/com/shekhargulati/app/Application.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,66 @@ | ||
package com.shekhargulati.app; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.autoconfigure.web.WebMvcRegistrationsAdapter; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; | ||
import org.springframework.web.servlet.mvc.condition.PatternsRequestCondition; | ||
import org.springframework.web.servlet.mvc.method.RequestMappingInfo; | ||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; | ||
|
||
@SpringBootApplication | ||
public class Application { | ||
|
||
@Value("${rest.api.base.path}") | ||
private String restApiBasePath; | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(Application.class, args); | ||
} | ||
|
||
@Bean | ||
public WebMvcConfigurer corsConfigurer() { | ||
return new WebMvcConfigurerAdapter() { | ||
@Override | ||
public void addCorsMappings(CorsRegistry registry) { | ||
registry.addMapping("/**").allowedMethods("*").allowedOrigins("http://localhost:4200"); | ||
} | ||
}; | ||
} | ||
|
||
@Bean | ||
public WebMvcRegistrationsAdapter webMvcRegistrationsHandlerMapping() { | ||
Application application = this; | ||
return new WebMvcRegistrationsAdapter() { | ||
@Override | ||
public RequestMappingHandlerMapping getRequestMappingHandlerMapping() { | ||
return new RequestMappingHandlerMapping() { | ||
|
||
@Override | ||
protected void registerHandlerMethod(Object handler, Method method, RequestMappingInfo mapping) { | ||
Class<?> beanType = method.getDeclaringClass(); | ||
RestController restApiController = beanType.getAnnotation(RestController.class); | ||
if (restApiController != null) { | ||
PatternsRequestCondition apiPattern = new PatternsRequestCondition(application.restApiBasePath) | ||
.combine(mapping.getPatternsCondition()); | ||
|
||
mapping = new RequestMappingInfo(mapping.getName(), apiPattern, | ||
mapping.getMethodsCondition(), mapping.getParamsCondition(), | ||
mapping.getHeadersCondition(), mapping.getConsumesCondition(), | ||
mapping.getProducesCondition(), mapping.getCustomCondition()); | ||
} | ||
|
||
super.registerHandlerMethod(handler, method, mapping); | ||
} | ||
}; | ||
} | ||
}; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
backend/src/main/java/com/shekhargulati/app/api/PingResource.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,20 @@ | ||
package com.shekhargulati.app.api; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
public class PingResource { | ||
|
||
@GetMapping(path = "/ping") | ||
public ResponseEntity<Map<String, String>> ping() { | ||
Map<String, String> map = new HashMap<>(); | ||
map.put("ping", "pong"); | ||
return new ResponseEntity<>(map, HttpStatus.OK); | ||
} | ||
} |
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 @@ | ||
rest.api.base.path=api |
16 changes: 16 additions & 0 deletions
16
backend/src/test/java/com/shekhargulati/app/ApplicationTests.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,16 @@ | ||
package com.shekhargulati.app; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest | ||
public class ApplicationTests { | ||
|
||
@Test | ||
public void contextLoads() { | ||
} | ||
|
||
} |
Oops, something went wrong.