mirror of
https://gitee.com/dcren/initializr.git
synced 2026-02-25 21:22:58 +08:00
Fix SpringBootServletInitializr import
As of Spring Boot 1.4.0.M3, `SpringBootServletInitializer` has been relocated to the `org.springframework.boot.web.support` package. This commit makes sure to use the new location if a project is generated for Spring Boot `1.4.0.M3` or higher. Closes gh-243
This commit is contained in:
@@ -46,6 +46,8 @@ class ProjectGenerator {
|
||||
|
||||
private static final VERSION_1_4_0_M2 = Version.parse('1.4.0.M2')
|
||||
|
||||
private static final VERSION_1_4_0_M3 = Version.parse('1.4.0.M3')
|
||||
|
||||
@Autowired
|
||||
ApplicationEventPublisher eventPublisher
|
||||
|
||||
@@ -227,6 +229,9 @@ class ProjectGenerator {
|
||||
// New testing stuff
|
||||
model['newTestInfrastructure'] = isNewTestInfrastructureAvailable(request)
|
||||
|
||||
// New Servlet Initializer location
|
||||
model['newServletInitializer'] = isNewServletInitializerAvailable(request)
|
||||
|
||||
model
|
||||
}
|
||||
|
||||
@@ -264,6 +269,11 @@ class ProjectGenerator {
|
||||
.compareTo(Version.safeParse(request.bootVersion)) <= 0
|
||||
}
|
||||
|
||||
private static boolean isNewServletInitializerAvailable(ProjectRequest request) {
|
||||
VERSION_1_4_0_M3
|
||||
.compareTo(Version.safeParse(request.bootVersion)) <= 0
|
||||
}
|
||||
|
||||
private byte[] doGenerateMavenPom(Map model) {
|
||||
template 'starter-pom.xml', model
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package ${packageName}
|
||||
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder
|
||||
import org.springframework.boot.context.web.SpringBootServletInitializer
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder<% if (newTestInfrastructure) { %>
|
||||
import org.springframework.boot.web.support.SpringBootServletInitializer<% } else { %>
|
||||
import org.springframework.boot.context.web.SpringBootServletInitializer<% } %>
|
||||
|
||||
class ServletInitializer extends SpringBootServletInitializer {
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package ${packageName};
|
||||
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.context.web.SpringBootServletInitializer;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;<% if (newTestInfrastructure) { %>
|
||||
import org.springframework.boot.web.support.SpringBootServletInitializer;<% } else { %>
|
||||
import org.springframework.boot.context.web.SpringBootServletInitializer;<% } %>
|
||||
|
||||
public class ServletInitializer extends SpringBootServletInitializer {
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package ${packageName}
|
||||
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder
|
||||
import org.springframework.boot.context.web.SpringBootServletInitializer
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder<% if (newTestInfrastructure) { %>
|
||||
import org.springframework.boot.web.support.SpringBootServletInitializer<% } else { %>
|
||||
import org.springframework.boot.context.web.SpringBootServletInitializer<% } %>
|
||||
|
||||
class ServletInitializer : SpringBootServletInitializer() {
|
||||
|
||||
|
||||
@@ -110,25 +110,36 @@ class ProjectGeneratorLanguageTests extends AbstractProjectGeneratorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test14TestClass() {
|
||||
public void springBoot14ServletInitializer() {
|
||||
def request = createProjectRequest()
|
||||
request.language = language
|
||||
request.packaging = 'war'
|
||||
request.bootVersion = '1.4.0.M3'
|
||||
def project = generateProject(request)
|
||||
project.sourceCodeAssert("src/main/$language/com/example/ServletInitializer.$extension")
|
||||
.equalsTo(new ClassPathResource("project/$language/spring-boot-1.4/ServletInitializer.$expectedExtension"))
|
||||
}
|
||||
|
||||
@Test
|
||||
public void springBoot14TestClass() {
|
||||
def request = createProjectRequest()
|
||||
request.language = language
|
||||
request.bootVersion = '1.4.0.M2'
|
||||
|
||||
def project = generateProject(request)
|
||||
project.sourceCodeAssert("src/test/$language/com/example/DemoApplicationTests.$extension")
|
||||
.equalsTo(new ClassPathResource("project/$language/test-1.4/DemoApplicationTests.$expectedExtension"))
|
||||
.equalsTo(new ClassPathResource("project/$language/spring-boot-1.4/DemoApplicationTests.$expectedExtension"))
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test14TestClassWeb() {
|
||||
public void springBoot14TestClassWeb() {
|
||||
def request = createProjectRequest('web')
|
||||
request.language = language
|
||||
request.bootVersion = '1.4.0.M2'
|
||||
|
||||
def project = generateProject(request)
|
||||
project.sourceCodeAssert("src/test/$language/com/example/DemoApplicationTests.$extension")
|
||||
.equalsTo(new ClassPathResource("project/$language/test-1.4/DemoApplicationTests.$expectedExtension"))
|
||||
.equalsTo(new ClassPathResource("project/$language/spring-boot-1.4/DemoApplicationTests.$expectedExtension"))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.example
|
||||
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder
|
||||
import org.springframework.boot.web.support.SpringBootServletInitializer
|
||||
|
||||
class ServletInitializer extends SpringBootServletInitializer {
|
||||
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
application.sources(DemoApplication)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.example;
|
||||
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.web.support.SpringBootServletInitializer;
|
||||
|
||||
public class ServletInitializer extends SpringBootServletInitializer {
|
||||
|
||||
@Override
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
return application.sources(DemoApplication.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.example
|
||||
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder
|
||||
import org.springframework.boot.web.support.SpringBootServletInitializer
|
||||
|
||||
class ServletInitializer : SpringBootServletInitializer() {
|
||||
|
||||
override fun configure(application: SpringApplicationBuilder) : SpringApplicationBuilder {
|
||||
return application.sources(DemoApplication::class.java)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user