Skip to content

Commit 84d9f71

Browse files
365 create auto configuration (#369)
* Add Multi Module example project * CreateAutoconfigurationAction is multimodule aware * Failing test, ehcache does not work with multi maven module spring app Co-authored-by: Andrei Shakirin <[email protected]>
1 parent 9f2a39e commit 84d9f71

File tree

19 files changed

+733
-28
lines changed

19 files changed

+733
-28
lines changed

applications/spring-shell/src/test/java/org/springframework/sbm/BootUpgrade_27_30_IntegrationTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ void migrateSimpleApplication() {
5757
verifyEhCacheVersionIsUpgraded();
5858
verifyJohnzonCoreDependencyIsUpgraded();
5959
}
60+
6061
private void buildProject() {
6162
executeMavenGoals(getTestDir(), "clean", "verify");
6263
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2021 - 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.sbm;
18+
19+
import org.junit.jupiter.api.Tag;
20+
import org.junit.jupiter.api.Test;
21+
22+
public class BootUpgrade_27_30_MultiModule_IntegrationTest extends IntegrationTestBaseClass {
23+
@Override
24+
protected String getTestSubDir() {
25+
return "boot-migration-27-30-multi-module";
26+
}
27+
28+
@Test
29+
@Tag("integration")
30+
void migrateMultiModuleApplication() {
31+
intializeTestProject();
32+
33+
scanProject();
34+
35+
applyRecipe("boot-2.7-3.0-dependency-version-update");
36+
37+
buildProject();
38+
}
39+
40+
private void buildProject() {
41+
executeMavenGoals(getTestDir(), "clean", "verify");
42+
}
43+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
**Features used in the current project**
2+
3+
* ehcache in pom is mentioned this helps validate our migration to spring 3 where ehcache classifier has to be used to resolve version.
4+
* Uses Constructor binding on classes which will be removed when migrating to Spring 3
5+
* Uses PagingAndSortingRepo interface where CrudRepo has been removed.
6+
* Uses properties that will be removed/moved on spring 3 migration
7+
* Uses micrometer packages which are moved to a new structure.
8+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<packaging>pom</packaging>
6+
<modules>
7+
<module>spring-app</module>
8+
</modules>
9+
10+
<parent>
11+
<groupId>org.springframework.boot</groupId>
12+
<artifactId>spring-boot-starter-parent</artifactId>
13+
<version>2.7.1</version>
14+
</parent>
15+
<groupId>com.example</groupId>
16+
<artifactId>boot-upgrade-27_30</artifactId>
17+
<version>0.0.1-SNAPSHOT</version>
18+
<name>boot-upgrade-27_30</name>
19+
<description>boot-upgrade-27_30</description>
20+
<properties>
21+
<java.version>17</java.version>
22+
</properties>
23+
24+
25+
<repositories>
26+
<repository>
27+
<id>spring-snapshot</id>
28+
<url>https://repo.spring.io/snapshot</url>
29+
<releases>
30+
<enabled>false</enabled>
31+
</releases>
32+
</repository>
33+
<repository>
34+
<id>spring-milestone</id>
35+
<url>https://repo.spring.io/milestone</url>
36+
<snapshots>
37+
<enabled>false</enabled>
38+
</snapshots>
39+
</repository>
40+
<repository>
41+
<id>spring-release</id>
42+
<url>https://repo.spring.io/release</url>
43+
<snapshots>
44+
<enabled>false</enabled>
45+
</snapshots>
46+
</repository>
47+
</repositories>
48+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2021 - 2022 the original author or authors.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ https://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<project xmlns="http://maven.apache.org/POM/4.0.0"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<parent>
22+
<artifactId>boot-upgrade-27_30</artifactId>
23+
<groupId>com.example</groupId>
24+
<version>0.0.1-SNAPSHOT</version>
25+
</parent>
26+
<modelVersion>4.0.0</modelVersion>
27+
28+
<artifactId>spring-app</artifactId>
29+
30+
<properties>
31+
<maven.compiler.source>17</maven.compiler.source>
32+
<maven.compiler.target>17</maven.compiler.target>
33+
</properties>
34+
<dependencies>
35+
<dependency>
36+
<groupId>org.springframework.boot</groupId>
37+
<artifactId>spring-boot-starter-web</artifactId>
38+
</dependency>
39+
<dependency>
40+
<groupId>org.ehcache</groupId>
41+
<artifactId>ehcache</artifactId>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.springframework.boot</groupId>
45+
<artifactId>spring-boot-starter-data-jpa</artifactId>
46+
</dependency>
47+
<dependency>
48+
<groupId>com.h2database</groupId>
49+
<artifactId>h2</artifactId>
50+
<scope>runtime</scope>
51+
</dependency>
52+
<dependency>
53+
<groupId>io.projectreactor</groupId>
54+
<artifactId>reactor-core</artifactId>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.apache.johnzon</groupId>
58+
<artifactId>johnzon-core</artifactId>
59+
</dependency>
60+
<dependency>
61+
<groupId>org.springframework.boot</groupId>
62+
<artifactId>spring-boot-starter-test</artifactId>
63+
<scope>test</scope>
64+
</dependency>
65+
</dependencies>
66+
67+
<build>
68+
<plugins>
69+
<plugin>
70+
<groupId>org.springframework.boot</groupId>
71+
<artifactId>spring-boot-maven-plugin</artifactId>
72+
</plugin>
73+
</plugins>
74+
</build>
75+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.hello;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.Configuration;
5+
6+
@Configuration
7+
public class GreetingConfig {
8+
9+
@Bean
10+
public String hello() {
11+
return "こんにちは";
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.springboot.example.ehcache;
2+
3+
import org.ehcache.event.CacheEvent;
4+
import org.ehcache.event.CacheEventListener;
5+
6+
public class EventLogger implements CacheEventListener<Object, Object> {
7+
@Override
8+
public void onEvent(CacheEvent<?, ?> cacheEvent) {
9+
System.out.println("My ehcache event listener is called");
10+
}
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.springboot.example.upgrade;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class BootUpgrade2730Application {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(BootUpgrade2730Application.class, args);
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.springboot.example.upgrade;
2+
3+
import org.springframework.boot.context.properties.ConfigurationProperties;
4+
import org.springframework.boot.context.properties.ConstructorBinding;
5+
6+
@ConfigurationProperties(prefix = "mail")
7+
@ConstructorBinding
8+
public class ConstructorBindingConfig {
9+
private String hostName;
10+
11+
public ConstructorBindingConfig(String hostName) {
12+
this.hostName = hostName;
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.springboot.example.upgrade;
2+
3+
import org.springframework.stereotype.Component;
4+
5+
import java.util.List;
6+
7+
@Component
8+
public class RepositoryController {
9+
private final StudentRepoPagingAndSorting studentRepoPagingAndSorting;
10+
11+
public RepositoryController(
12+
StudentRepoPagingAndSorting studentRepoPagingAndSorting) {
13+
this.studentRepoPagingAndSorting = studentRepoPagingAndSorting;
14+
}
15+
16+
public void actWithRepositories() {
17+
studentRepoPagingAndSorting.save(new Student());
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package org.springboot.example.upgrade;
2+
3+
import javax.persistence.Entity;
4+
import javax.persistence.Id;
5+
6+
@Entity
7+
public class Student {
8+
@Id
9+
private long id;
10+
private String name;
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package org.springboot.example.upgrade;
2+
3+
import org.springframework.data.repository.PagingAndSortingRepository;
4+
5+
public interface StudentRepoPagingAndSorting extends PagingAndSortingRepository<Student, Long> {
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.hello.GreetingConfig

0 commit comments

Comments
 (0)