Skip to content

Commit ed75a4a

Browse files
committed
Spring Boot sample
Signed-off-by: Allann Jones
1 parent b56c94b commit ed75a4a

File tree

22 files changed

+686
-47
lines changed

22 files changed

+686
-47
lines changed

.gitignore

Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -91,48 +91,13 @@ java-jdbc/jdbc-mssql/resources/sqljdbc_4.2/
9191
java-jni/*.h
9292
java-jni/*.dll
9393

94-
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
95-
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
96-
97-
# User-specific stuff
98-
**/.idea/**/workspace.xml
99-
**/.idea/**/tasks.xml
100-
**/.idea/**/usage.statistics.xml
101-
**/.idea/**/dictionaries
102-
**/.idea/**/shelf
103-
104-
# Generated files
105-
**/.idea/**/contentModel.xml
106-
107-
# Sensitive or high-churn files
108-
**/.idea/**/dataSources/
109-
**/.idea/**/dataSources.ids
110-
**/.idea/**/dataSources.local.xml
111-
**/.idea/**/sqlDataSources.xml
112-
**/.idea/**/dynamic.xml
113-
**/.idea/**/uiDesigner.xml
114-
**/.idea/**/dbnavigator.xml
115-
116-
# Gradle
117-
**/.idea/**/gradle.xml
118-
**/.idea/**/libraries
119-
120-
# Gradle and Maven with auto-import
121-
# When using Gradle or Maven with auto-import, you should exclude module files,
122-
# since they will be recreated, and may cause churn. Uncomment if using
123-
# auto-import.
124-
# .idea/modules.xml
125-
# .idea/*.iml
126-
# .idea/modules
127-
# *.iml
128-
# *.ipr
94+
.idea/
95+
*.iml
96+
*.ipr
12997

13098
# CMake
13199
cmake-build-*/
132100

133-
# Mongo Explorer plugin
134-
**/.idea/**/mongoSettings.xml
135-
136101
# File-based project format
137102
*.iws
138103

@@ -145,17 +110,8 @@ out/
145110
# JIRA plugin
146111
atlassian-ide-plugin.xml
147112

148-
# Cursive Clojure plugin
149-
**/.idea/replstate.xml
150-
151113
# Crashlytics plugin (for Android Studio and IntelliJ)
152114
com_crashlytics_export_strings.xml
153115
crashlytics.properties
154116
crashlytics-build.properties
155117
fabric.properties
156-
157-
# Editor-based Rest Client
158-
**/.idea/httpRequests
159-
160-
# Android studio 3.1+ serialized cache file
161-
**/.idea/caches/build_file_checksums.ser

java-spring-boot/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Java samples
2+
3+
## Spring Boot
4+
5+
### Build
6+
7+
mvn clean install
8+
9+
### Deploy
10+
11+
mvn spring-boot:run

java-spring-boot/pom.xml

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>materials</groupId>
6+
<artifactId>materials</artifactId>
7+
<version>0.0.1</version>
8+
<packaging>jar</packaging>
9+
<parent>
10+
<groupId>org.springframework.boot</groupId>
11+
<artifactId>spring-boot-starter-parent</artifactId>
12+
<version>2.2.5.RELEASE</version>
13+
<relativePath />
14+
</parent>
15+
<dependencies>
16+
<!-- Spring -->
17+
<dependency>
18+
<groupId>org.springframework.boot</groupId>
19+
<artifactId>spring-boot-starter-web</artifactId>
20+
</dependency>
21+
<dependency>
22+
<groupId>org.springframework.boot</groupId>
23+
<artifactId>spring-boot-starter-tomcat</artifactId>
24+
<scope>provided</scope>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.springframework.boot</groupId>
28+
<artifactId>spring-boot-starter-data-jpa</artifactId>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.springframework.boot</groupId>
32+
<artifactId>spring-boot-starter-thymeleaf</artifactId>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.springframework.boot</groupId>
36+
<artifactId>spring-boot-starter-test</artifactId>
37+
<scope>test</scope>
38+
</dependency>
39+
<!-- MySQL -->
40+
<dependency>
41+
<groupId>mysql</groupId>
42+
<artifactId>mysql-connector-java</artifactId>
43+
<version>8.0.16</version>
44+
</dependency>
45+
<!-- JUnit -->
46+
<dependency>
47+
<groupId>org.junit.jupiter</groupId>
48+
<artifactId>junit-jupiter-api</artifactId>
49+
<version>5.1.0</version>
50+
<scope>test</scope>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.junit.jupiter</groupId>
54+
<artifactId>junit-jupiter-engine</artifactId>
55+
<version>5.1.0</version>
56+
<scope>test</scope>
57+
</dependency>
58+
<dependency>
59+
<groupId>org.junit.vintage</groupId>
60+
<artifactId>junit-vintage-engine</artifactId>
61+
<version>5.1.0</version>
62+
<scope>test</scope>
63+
</dependency>
64+
<dependency>
65+
<groupId>org.junit.platform</groupId>
66+
<artifactId>junit-platform-launcher</artifactId>
67+
<version>1.1.0</version>
68+
<scope>test</scope>
69+
</dependency>
70+
<dependency>
71+
<groupId>org.junit.platform</groupId>
72+
<artifactId>junit-platform-runner</artifactId>
73+
<version>1.1.0</version>
74+
<scope>test</scope>
75+
</dependency>
76+
<!-- Log4J -->
77+
<dependency>
78+
<groupId>org.apache.logging.log4j</groupId>
79+
<artifactId>log4j-api</artifactId>
80+
<version>2.13.1</version>
81+
</dependency>
82+
<dependency>
83+
<groupId>org.apache.logging.log4j</groupId>
84+
<artifactId>log4j-core</artifactId>
85+
<version>2.13.1</version>
86+
</dependency>
87+
<dependency>
88+
<groupId>com.lmax</groupId>
89+
<artifactId>disruptor</artifactId>
90+
<version>3.4.2</version>
91+
</dependency>
92+
</dependencies>
93+
<properties>
94+
<!-- tomcat.version>8.5.37</tomcat.version -->
95+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
96+
<start-class>br.com.olivum.materials.Application</start-class>
97+
<java.version>11</java.version>
98+
</properties>
99+
<build>
100+
<finalName>materials</finalName>
101+
<sourceDirectory>src/main/java</sourceDirectory>
102+
<plugins>
103+
<plugin>
104+
<groupId>org.springframework.boot</groupId>
105+
<artifactId>spring-boot-maven-plugin</artifactId>
106+
</plugin>
107+
<plugin>
108+
<artifactId>maven-war-plugin</artifactId>
109+
<version>3.2.3</version>
110+
<configuration>
111+
<!-- warSourceDirectory>src/main/webapp</warSourceDirectory -->
112+
<failOnMissingWebXml>false</failOnMissingWebXml>
113+
</configuration>
114+
</plugin>
115+
<plugin>
116+
<artifactId>maven-compiler-plugin</artifactId>
117+
<version>3.8.1</version>
118+
<configuration>
119+
<release>11</release>
120+
</configuration>
121+
</plugin>
122+
<plugin>
123+
<groupId>org.apache.tomcat.maven</groupId>
124+
<artifactId>tomcat7-maven-plugin</artifactId>
125+
<version>2.2</version>
126+
<configuration>
127+
<path>/materials</path>
128+
<update>true</update>
129+
<charset>UTF-8</charset>
130+
<port>8080</port>
131+
</configuration>
132+
</plugin>
133+
</plugins>
134+
</build>
135+
</project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package br.com.olivum.materials;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
5+
import org.springframework.boot.autoconfigure.SpringBootApplication;
6+
import org.springframework.boot.autoconfigure.domain.EntityScan;
7+
import org.springframework.context.annotation.ComponentScan;
8+
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
9+
10+
@SpringBootApplication
11+
@EnableAutoConfiguration
12+
@EntityScan(basePackages = { "br.com.olivum.materials" })
13+
@EnableJpaRepositories(basePackages = { "br.com.olivum.materials" })
14+
@ComponentScan(basePackages = {"br.com.olivum.materials"})
15+
public class Application {
16+
public static void main(String[] args) {
17+
System.out.println("main()");
18+
19+
SpringApplication.run(Application.class, args);
20+
}
21+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package br.com.olivum.materials.config;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.ComponentScan;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
7+
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
8+
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
9+
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
10+
import org.springframework.web.servlet.view.InternalResourceViewResolver;
11+
12+
@Configuration
13+
@EnableWebMvc
14+
@ComponentScan(basePackages = "example.com")
15+
public class WebConfiguration implements WebMvcConfigurer {
16+
private static final String[] CLASSPATH_RESOURCE_LOCATIONS = {
17+
"classpath:/META-INF/resources/", "classpath:/resources/",
18+
"classpath:/static/", "classpath:/public/" };
19+
20+
@Override
21+
public void addResourceHandlers(ResourceHandlerRegistry registry) {
22+
registry.addResourceHandler("/**").addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS);
23+
}
24+
25+
@Override
26+
public void addViewControllers(ViewControllerRegistry registry) {
27+
registry.addViewController("/").setViewName("forward:/index.html");
28+
}
29+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package br.com.olivum.materials.controller;
2+
3+
import org.springframework.boot.web.servlet.error.ErrorAttributes;
4+
import org.springframework.boot.web.servlet.error.ErrorController;
5+
import org.springframework.stereotype.Controller;
6+
7+
/**
8+
* Basic Controller which is called for unhandled errors
9+
*/
10+
@Controller
11+
public class AppErrorController implements ErrorController {
12+
13+
/**
14+
* Error Attributes in the Application
15+
*/
16+
private ErrorAttributes errorAttributes;
17+
18+
private final static String ERROR_PATH = "/error";
19+
20+
/**
21+
* Controller for the Error Controller
22+
*
23+
* @param errorAttributes
24+
*/
25+
public AppErrorController(ErrorAttributes errorAttributes) {
26+
this.errorAttributes = errorAttributes;
27+
}
28+
29+
@Override
30+
public String getErrorPath() {
31+
return ERROR_PATH;
32+
}
33+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package br.com.olivum.materials.controller;
2+
3+
import br.com.olivum.materials.protocol.RequestResponse;
4+
import br.com.olivum.materials.protocol.RequestResponseList;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.stereotype.Controller;
7+
import org.springframework.web.bind.annotation.PathVariable;
8+
import org.springframework.web.bind.annotation.RequestBody;
9+
import org.springframework.web.bind.annotation.RequestMapping;
10+
import org.springframework.web.bind.annotation.RequestMethod;
11+
import org.springframework.web.bind.annotation.ResponseBody;
12+
13+
import br.com.olivum.materials.model.Material;
14+
import br.com.olivum.materials.service.MaterialsService;
15+
16+
@Controller
17+
@RequestMapping(value = "/rest/material")
18+
public class MaterialsController {
19+
@Autowired
20+
MaterialsService materialsService;
21+
22+
@RequestMapping(value = "", method = RequestMethod.GET, produces = "application/json")
23+
@ResponseBody
24+
public RequestResponseList getMaterialsList() {
25+
System.out.println("getMaterialsList()");
26+
27+
RequestResponseList requestResponseList = new RequestResponseList();
28+
29+
requestResponseList.setStatus(0);
30+
requestResponseList.setData(materialsService.getList());
31+
32+
return requestResponseList;
33+
}
34+
35+
@RequestMapping(method = RequestMethod.POST, produces = "application/json")
36+
@ResponseBody
37+
public RequestResponse newMaterial(@RequestBody Material material) {
38+
System.out.println("newMaterial()");
39+
40+
System.out.println("material: " + material.getName());
41+
42+
materialsService.saveMaterial(material);
43+
44+
RequestResponse requestResponse = new RequestResponse();
45+
46+
requestResponse.setData(material);
47+
48+
return requestResponse;
49+
}
50+
51+
@RequestMapping(value = "/edit/{id}", method = RequestMethod.POST, produces = "application/json")
52+
@ResponseBody
53+
public Material updateMaterial(@PathVariable("id") long id, @RequestBody Material material) {
54+
System.out.println("updateMaterial()");
55+
56+
System.out.println("material: " + material.getName());
57+
58+
//material.setId(id);
59+
60+
materialsService.updateMaterial(material);
61+
62+
return material;
63+
}
64+
65+
@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = "application/json")
66+
@ResponseBody
67+
public Material getMaterialInfo(@PathVariable("id") long id) {
68+
System.out.println("getMaterialInfo()");
69+
70+
Material material = materialsService.getItem(id);
71+
72+
return material;
73+
}
74+
75+
@RequestMapping(value = "/del", method = RequestMethod.POST, produces = "application/json")
76+
@ResponseBody
77+
public Boolean deleteMaterial(@RequestBody Material material) {
78+
System.out.println("deleteMaterial()");
79+
80+
return materialsService.deleteItem(material.getId());
81+
}
82+
}

0 commit comments

Comments
 (0)