Skip to content

Commit 1def033

Browse files
committed
Add backend-java-spring
1 parent a7c76cf commit 1def033

File tree

8 files changed

+261
-0
lines changed

8 files changed

+261
-0
lines changed

backend-java-spring/.gitignore

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Fichiers compilés
2+
*.class
3+
*.war
4+
*.jar
5+
*.ear
6+
7+
# Répertoires de build
8+
/bin/
9+
/build/
10+
/out/
11+
target/
12+
*/build/
13+
14+
# Logs et fichiers temporaires
15+
*.log
16+
*.tmp
17+
hs_err_pid*
18+
19+
# Paramètres de l'IDE Eclipse
20+
/.classpath
21+
/.project
22+
/.settings/
23+
*.iml
24+
.idea/
25+
.vscode/
26+
27+
# Maven
28+
/.mvn/
29+
.mvn/
30+
pom.xml.tag
31+
pom.xml.releaseBackup
32+
pom.xml.versionsBackup
33+
pom.xml.next
34+
release.properties
35+
36+
# Gradle
37+
.gradle/
38+
build/
39+
!gradle/wrapper/gradle-wrapper.jar
40+
gradle-app.setting
41+
42+
# Fichiers spécifiques à Tomcat
43+
/.tomcat/
44+
45+
# Cache et fichiers temporaires
46+
.DS_Store
47+
Thumbs.db

backend-java-spring/pom.xml

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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+
5+
<modelVersion>4.0.0</modelVersion>
6+
<groupId>com.ganatan</groupId>
7+
<artifactId>backend-java-spring-starter</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>war</packaging>
10+
11+
<properties>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13+
<maven.compiler.source>21</maven.compiler.source>
14+
<maven.compiler.target>21</maven.compiler.target>
15+
<maven.compiler.release>21</maven.compiler.release>
16+
</properties>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.springframework</groupId>
21+
<artifactId>spring-webmvc</artifactId>
22+
<version>6.2.4</version>
23+
</dependency>
24+
<dependency>
25+
<groupId>org.springframework</groupId>
26+
<artifactId>spring-test</artifactId>
27+
<version>6.2.4</version>
28+
<scope>test</scope>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.junit.jupiter</groupId>
32+
<artifactId>junit-jupiter</artifactId>
33+
<version>5.10.0</version>
34+
<scope>test</scope>
35+
</dependency>
36+
<dependency>
37+
<groupId>com.fasterxml.jackson.core</groupId>
38+
<artifactId>jackson-databind</artifactId>
39+
<version>2.18.3</version>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.apache.tomcat.embed</groupId>
43+
<artifactId>tomcat-embed-core</artifactId>
44+
<version>11.0.5</version>
45+
</dependency>
46+
<dependency>
47+
<groupId>jakarta.servlet</groupId>
48+
<artifactId>jakarta.servlet-api</artifactId>
49+
<version>6.1.0</version>
50+
<scope>provided</scope>
51+
</dependency>
52+
</dependencies>
53+
54+
<build>
55+
<finalName>backend-java-spring-starter</finalName>
56+
<plugins>
57+
<!-- <plugin>
58+
<groupId>org.apache.maven.plugins</groupId>
59+
<artifactId>maven-compiler-plugin</artifactId>
60+
<version>3.13.0</version>
61+
</plugin>
62+
<plugin>
63+
<groupId>org.apache.maven.plugins</groupId>
64+
<artifactId>maven-war-plugin</artifactId>
65+
<version>3.4.0</version>
66+
</plugin>
67+
--> <plugin>
68+
<groupId>org.jacoco</groupId>
69+
<artifactId>jacoco-maven-plugin</artifactId>
70+
<version>0.8.10</version>
71+
<executions>
72+
<execution>
73+
<goals>
74+
<goal>prepare-agent</goal>
75+
</goals>
76+
</execution>
77+
<execution>
78+
<id>report</id>
79+
<phase>verify</phase>
80+
<goals>
81+
<goal>report</goal>
82+
</goals>
83+
</execution>
84+
</executions>
85+
</plugin>
86+
<!-- <plugin>
87+
<groupId>org.apache.maven.plugins</groupId>
88+
<artifactId>maven-surefire-plugin</artifactId>
89+
<version>3.0.0-M7</version>
90+
</plugin>
91+
--> </plugins>
92+
</build>
93+
94+
</project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.ganatan.config;
2+
3+
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
4+
5+
public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
6+
7+
@Override
8+
protected Class<?>[] getRootConfigClasses() {
9+
return null;
10+
}
11+
12+
@Override
13+
protected Class<?>[] getServletConfigClasses() {
14+
return new Class<?>[]{WebConfig.class};
15+
}
16+
17+
@Override
18+
protected String[] getServletMappings() {
19+
return new String[]{"/"};
20+
}
21+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.ganatan.config;
2+
3+
import org.springframework.context.annotation.ComponentScan;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
6+
7+
@Configuration
8+
@EnableWebMvc
9+
@ComponentScan(basePackages = "com.ganatan")
10+
public class WebConfig {
11+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.ganatan.controllers;
2+
3+
import com.ganatan.models.Person;
4+
import org.springframework.web.bind.annotation.GetMapping;
5+
import org.springframework.web.bind.annotation.RequestMapping;
6+
import org.springframework.web.bind.annotation.RestController;
7+
import java.util.List;
8+
9+
@RestController
10+
@RequestMapping("/")
11+
public class HomeController {
12+
@GetMapping
13+
public List<Person> getPersons() {
14+
return List.of(
15+
new Person(1, "Christopher Nolan", "London"),
16+
new Person(2, "Quentin Tarantino", "Knoxville"),
17+
new Person(3, "Martin Scorsese", "New York"),
18+
new Person(4, "Steven Spielberg", "Cincinnati")
19+
);
20+
}
21+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.ganatan.models;
2+
3+
public class Person {
4+
private int id;
5+
private String name;
6+
private String city;
7+
8+
public Person(int id, String name, String city) {
9+
this.id = id;
10+
this.name = name;
11+
this.city = city;
12+
}
13+
14+
public int getId() {
15+
return id;
16+
}
17+
18+
public String getName() {
19+
return name;
20+
}
21+
22+
public String getCity() {
23+
return city;
24+
}
25+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.ganatan.tools;
2+
3+
import java.io.File;
4+
5+
public class GenerateProjectStructure {
6+
public static void main(String[] args) {
7+
String projectPath = ".";
8+
File projectDir = new File(projectPath);
9+
10+
if (projectDir.exists() && projectDir.isDirectory()) {
11+
listFiles(projectDir, 0);
12+
} else {
13+
System.out.println("Invalid project directory: " + projectPath);
14+
}
15+
}
16+
17+
private static void listFiles(File directory, int level) {
18+
File[] files = directory.listFiles();
19+
if (files == null)
20+
return;
21+
22+
for (File file : files) {
23+
System.out.println(" ".repeat(level) + "- " + file.getName());
24+
if (file.isDirectory()) {
25+
listFiles(file, level + 1);
26+
}
27+
}
28+
}
29+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.ganatan.controllers;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import static org.junit.jupiter.api.Assertions.assertTrue;
6+
7+
class HomeControllerTest {
8+
9+
@Test
10+
void shouldAlwaysPass() {
11+
assertTrue(true);
12+
}
13+
}

0 commit comments

Comments
 (0)