Skip to content

Commit 28c72c9

Browse files
committedFeb 12, 2023
Test H2 access and logging
1 parent a4f2529 commit 28c72c9

File tree

6 files changed

+38
-29
lines changed

6 files changed

+38
-29
lines changed
 

‎.gitignore

+8-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
*.class
33
*.jar
44
*.war
5-
# JVM crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
5+
# JVM crash logs
66
hs_err_pid*
77
replay_pid*
88

@@ -18,7 +18,8 @@ buildNumber.properties
1818
.mvn/timing.properties
1919
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
2020
.mvn/wrapper/maven-wrapper.jar
21-
# Spring Boot
21+
22+
### Spring Boot ###
2223
!**/src/main/**/target/
2324
!**/src/test/**/target/
2425

@@ -53,5 +54,8 @@ build/
5354
### BlueJ files ##
5455
*.ctxt
5556

56-
### Tomcat ###
57-
tomcat/
57+
## Logs
58+
logs/
59+
60+
## DB
61+
database/

‎README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
## Refs
22

3-
* [How to log](https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/html/howto.html#howto.logging)
4-
* [Logging features](https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/html/features.html#features.logging)
5-
* [How to access databases](https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/html/howto.html#howto.data-access)
3+
* [DDD / Hexagonal Architecture](https://www.baeldung.com/hexagonal-architecture-ddd-spring)
4+
* JPA + H2 - [How to access databases](https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/html/howto.html#howto.data-access)
65
* [Spring Boot Actuator](https://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/html/actuator.html#actuator)
76

87
## Guides

‎pom.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525

2626
<dependency>
2727
<groupId>org.springframework.boot</groupId>
28-
<artifactId>spring-boot-starter-test</artifactId>
29-
<scope>test</scope>
28+
<artifactId>spring-boot-starter-data-jpa</artifactId>
3029
</dependency>
3130

3231
<dependency>
33-
<groupId>org.springframework.boot</groupId>
34-
<artifactId>spring-boot-starter-actuator</artifactId>
32+
<groupId>com.h2database</groupId>
33+
<artifactId>h2</artifactId>
34+
<scope>runtime</scope>
3535
</dependency>
3636
</dependencies>
3737

‎src/main/java/baioc/dontpad/Controller.java

+14
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,27 @@
22

33
import org.springframework.web.bind.annotation.GetMapping;
44
import org.springframework.web.bind.annotation.RestController;
5+
import org.slf4j.LoggerFactory;
6+
import org.slf4j.Logger;
57

68
@RestController
79
public class Controller {
810

11+
private Logger logger = LoggerFactory.getLogger(getClass());
12+
913
@GetMapping("/")
1014
public String index() {
1115
return "Hello, Spring World!";
1216
}
1317

18+
@GetMapping("/log")
19+
public String testLog() {
20+
logger.error("this is a error-level log message");
21+
logger.warn("this is a warn-level log message");
22+
logger.info("this is a info-level log message");
23+
logger.debug("this is a debug-level log message");
24+
logger.trace("this is a trace-level log message");
25+
return "something was logged";
26+
}
27+
1428
}
+10-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
server.port=8080
2-
3-
server.tomcat.basedir=tomcat
41
server.tomcat.accesslog.enabled=true
5-
server.undertow.options.server.record-request-start-time=true
2+
server.tomcat.basedir=logs/tomcat
3+
server.tomcat.accesslog.max-days=180
4+
5+
logging.file.name=logs/dontpad/root.log
6+
7+
spring.jpa.open-in-view=false
8+
9+
spring.datasource.url=jdbc:h2:./database/dontpad
10+
spring.datasource.username=sa
11+
spring.datasource.password=

‎src/test/java/baioc/dontpad/ApplicationTests.java

-14
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.