mirror of
https://github.com/OtusTeam/Spring.git
synced 2026-06-20 11:14:34 +00:00
2022-05 spring-06-avdanced-config example updated
This commit is contained in:
@@ -19,5 +19,6 @@
|
||||
<module>test-configuration-solution-1</module>
|
||||
<module>test-configuration-solution-2</module>
|
||||
<module>test-configuration-solution-3</module>
|
||||
<module>test-caching-demo</module>
|
||||
</modules>
|
||||
</project>
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
1638867120546:p
|
||||
1638867124184:l
|
||||
1638867125867:p
|
||||
1638867146689:l
|
||||
1638867147641:p
|
||||
1655216108320:l
|
||||
1655216109269:p
|
||||
1655216123518:l
|
||||
1655216124571:p
|
||||
@@ -0,0 +1,32 @@
|
||||
# Compiled class file
|
||||
*.class
|
||||
|
||||
# Log file
|
||||
*.log
|
||||
|
||||
# BlueJ files
|
||||
*.ctxt
|
||||
|
||||
# Mobile Tools for Java (J2ME)
|
||||
.mtj.tmp/
|
||||
|
||||
# Package Files #
|
||||
*.jar
|
||||
*.war
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
|
||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||
hs_err_pid*
|
||||
|
||||
#other
|
||||
*.bat
|
||||
*/.idea
|
||||
*.iml
|
||||
*/target
|
||||
|
||||
.idea
|
||||
*.iml
|
||||
target
|
||||
@@ -0,0 +1,49 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.7.0</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<groupId>ru.otus.example</groupId>
|
||||
<artifactId>test-caching-demo</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<java.version>11</java.version>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package ru.otus.example.testconfigurationdemo;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@SpringBootApplication
|
||||
public class TestConfigurationDemoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(TestConfigurationDemoApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package ru.otus.example.testconfigurationdemo.statefulservices;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class Service1 {
|
||||
@Getter
|
||||
private final String name = "Service1";
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String state = "State1";
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package ru.otus.example.testconfigurationdemo.statefulservices;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class Service2 {
|
||||
@Getter
|
||||
private final String name = "Service2";
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private String state = "State2";
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package ru.otus.example.testconfigurationdemo.statefulservices;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
//@SpringBootTest(classes = {Service1.class, Service2.class})
|
||||
//@TestPropertySource("classpath:test.properties")
|
||||
//@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)
|
||||
@SpringBootTest
|
||||
class IntegrationTest1 {
|
||||
|
||||
@Autowired
|
||||
private Service1 service1;
|
||||
|
||||
//@MockBean
|
||||
@Autowired
|
||||
private Service2 service2;
|
||||
|
||||
@Test
|
||||
void test1() {
|
||||
System.out.println(service1.getName() + ": " + service1.getState());
|
||||
System.out.println(service2.getName() + ": " + service2.getState());
|
||||
|
||||
service1.setState("State3");
|
||||
service2.setState("State4");
|
||||
}
|
||||
|
||||
@Test
|
||||
void test2() {
|
||||
System.out.println(service1.getName() + ": " + service1.getState());
|
||||
System.out.println(service2.getName() + ": " + service2.getState());
|
||||
|
||||
service1.setState("State5");
|
||||
service2.setState("State6");
|
||||
}
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
package ru.otus.example.testconfigurationdemo.statefulservices;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
class IntegrationTest2 {
|
||||
|
||||
@Autowired
|
||||
private Service1 service1;
|
||||
|
||||
@Autowired
|
||||
private Service2 service2;
|
||||
|
||||
@Test
|
||||
void test3() {
|
||||
System.out.println(service1.getName() + ": " + service1.getState());
|
||||
System.out.println(service2.getName() + ": " + service2.getState());
|
||||
|
||||
service1.setState("State7");
|
||||
service2.setState("State8");
|
||||
}
|
||||
|
||||
@Test
|
||||
void test4() {
|
||||
System.out.println(service1.getName() + ": " + service1.getState());
|
||||
System.out.println(service2.getName() + ": " + service2.getState());
|
||||
|
||||
service1.setState("State9");
|
||||
service2.setState("State10");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
any.prop=10
|
||||
Reference in New Issue
Block a user