Skip to content

Commit

Permalink
clean the war sample.
Browse files Browse the repository at this point in the history
  • Loading branch information
hantsy committed Dec 3, 2017
1 parent 633eb1f commit 59a2f85
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,9 @@
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.thymeleaf.spring5.context.webflux.ReactiveDataDriverContextVariable;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@SpringBootApplication
public class DemoApplication {
Expand Down
144 changes: 77 additions & 67 deletions war/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<jetty.http.port>8080</jetty.http.port>
</properties>

<dependencies>
Expand Down Expand Up @@ -128,78 +127,16 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<version>2.20.1</version>
<configuration>
<printSummary>true</printSummary>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<excludes>
<exclude>**/IntegrationTests</exclude>
<exclude>**/IntegrationTests*</exclude>
</excludes>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.20</version>
<configuration>
<includes>
<include>**/IntegrationTests</include>
</includes>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.6.v20170531</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<stopPort>8005</stopPort>
<stopKey>STOP</stopKey>
<webApp>
<contextPath>/</contextPath>
</webApp>
<httpConnector>
<port>8080</port>
</httpConnector>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>stop</goal>
<goal>start</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
Expand All @@ -210,6 +147,7 @@
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.6.5</version>
<configuration>
<container>
<containerId>tomcat8x</containerId>
Expand All @@ -218,15 +156,87 @@

<configuration>
<properties>
<cargo.servlet.port>9000</cargo.servlet.port>
<cargo.servlet.port>8080</cargo.servlet.port>
<cargo.logging>high</cargo.logging>
</properties>
</configuration>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>integration</id>
<build>

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<includes>
<include>**/IntegrationTests*</include>
</includes>
<skipITs>${skipTests}</skipITs>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.7.v20170914</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<stopPort>8005</stopPort>
<stopKey>STOP</stopKey>
<webApp>
<contextPath>/</contextPath>
</webApp>
<httpConnector>
<port>9000</port>
</httpConnector>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>stop</goal>
<goal>start</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<repositories>
<repository>
<id>spring-snapshots</id>
Expand Down
28 changes: 26 additions & 2 deletions war/src/main/java/com/example/demo/AppIntializer.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package com.example.demo;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.http.server.reactive.HttpHandler;
import org.springframework.http.server.reactive.ServletHttpHandlerAdapter;
import org.springframework.web.reactive.support.AbstractAnnotationConfigDispatcherHandlerInitializer;
import org.springframework.util.Assert;
import org.springframework.web.server.adapter.AbstractReactiveWebInitializer;
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;

// There is a bug to stop security WebFilter registraion before 5.0.2.
// A workaround: https://stackoverflow.com/questions/46325632/how-to-activate-spring-security-in-a-webflux-war-application
public class AppIntializer extends AbstractAnnotationConfigDispatcherHandlerInitializer {
/*public class AppIntializer extends AbstractAnnotationConfigDispatcherHandlerInitializer {
@Override
protected Class<?>[] getConfigClasses() {
Expand Down Expand Up @@ -40,4 +43,25 @@ protected void registerDispatcherHandler(ServletContext servletContext) {
customizeRegistration(registration);
}
}*/

//in Spring 5.0.2, a new AbstractReactiveWebInitializer introduced.
public class AppIntializer extends AbstractReactiveWebInitializer {

@Override
protected ApplicationContext createApplicationContext() {
Class<?>[] configClasses = getConfigClasses();
Assert.notEmpty(configClasses, "No Spring configuration provided.");
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configClasses);
return context;
}

@Override
protected Class<?>[] getConfigClasses() {
return new Class[]{
WebConfig.class,
SecurityConfig.class
};
}

}
2 changes: 1 addition & 1 deletion war/src/test/java/com/example/demo/IntegrationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void setup() {
this.rest = WebTestClient
.bindToServer()
.responseTimeout(Duration.ofDays(1))
.baseUrl("http://localhost:8080")
.baseUrl("http://localhost:9000")
.filter(basicAuthentication())
.build();
}
Expand Down

0 comments on commit 59a2f85

Please sign in to comment.