Skip to content

Commit

Permalink
Modify example application for Spring Boot
Browse files Browse the repository at this point in the history
  • Loading branch information
jjohannes committed Dec 4, 2023
1 parent 8f4c321 commit abd84c1
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 42 deletions.
9 changes: 5 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ plugins {
id("org.example.application")
}

application {
mainClass.set("org.example.product.app.Application")
}

dependencies {
providedCompile("jakarta.servlet:jakarta.servlet-api")

Expand All @@ -18,6 +14,10 @@ dependencies {
implementation("com.google.inject.extensions:guice-servlet")
implementation("com.google.inject:guice")
implementation("org.slf4j:slf4j-api")
implementation("org.springframework.boot:spring-boot")
implementation("org.springframework.boot:spring-boot-autoconfigure")
implementation("org.springframework:spring-context")
implementation("org.springframework:spring-web")

mockApiImplementation(project(path))
mockApiImplementation("com.google.guava:guava")
Expand All @@ -29,4 +29,5 @@ dependencies {
endToEndTestImplementation("org.junit.jupiter:junit-jupiter-api")

runtimeOnly("org.slf4j:slf4j-simple")
runtimeOnly("org.springframework.boot:spring-boot-starter-web")
}
34 changes: 20 additions & 14 deletions app/src/main/java/org/example/product/app/AppServlet.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
package org.example.product.app;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.InputStreamReader;

import static java.util.Objects.requireNonNull;

@RestController
public class AppServlet {

@WebServlet("/check")
public class AppServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
res.setContentType("text/html");
PrintWriter pw = res.getWriter();
pw.println("<html><body>");
pw.println("App is running...");
pw.println("</body></html>");
pw.close();
@GetMapping("/")
public String index() throws IOException {
new MainModule().run();
String version = new BufferedReader(new InputStreamReader(
requireNonNull(AppServlet.class.getResourceAsStream("/version.txt"))
)).readLine();
return "<html><body>" +
"App is running... !!!!" +
"<br/>Version " + version +
"</body></html>";
}
}
8 changes: 5 additions & 3 deletions app/src/main/java/org/example/product/app/Application.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package org.example.product.app;

import java.io.IOException;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {

public static void main(String[] args) throws IOException {
new MainModule().run();
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
3 changes: 2 additions & 1 deletion gradle/platform/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies {
api(platform("org.junit:junit-bom:5.7.2")) { (this as ExternalModuleDependency).version { reject("[5.8.0,)") } } // Do not Upgrade to 5.8: https://github.com/gradle/gradle/issues/18627
api(platform("org.mockito:mockito-bom:4.5.1"))
api(platform("org.slf4j:slf4j-parent:1.7.36")) { because ("see Slf4jPlatformRule") } // Parent as Anchor for Alignment BOM
api(platform("org.springframework.boot:spring-boot-dependencies:2.7.18"))
}

dependencies.constraints {
Expand All @@ -20,7 +21,7 @@ dependencies.constraints {
api("jakarta.inject:jakarta.inject-api:1.0.5") { version { reject("[2.0.0,)") } } // Upgrade to 2.x requires newer Jakarta APIs
api("jakarta.servlet:jakarta.servlet-api:4.0.4") { version { reject("[5.0.0,)") } } // Stay Tomcat 8 compatible
api("org.apache.commons:commons-lang3:3.9")
api("org.apache.solr:solr-solrj:7.7.3") { version { reject("[8.0.0,)") } } // API changes in 8 require production code changes
api("org.apache.solr:solr-solrj:7.7.3!!") { version { reject("[8.0.0,)") } } // API changes in 8 require production code changes
api("org.apache.velocity:velocity-engine-core:2.3")
api("org.apache.zookeeper:zookeeper:3.8.0")
api("org.assertj:assertj-core:3.22.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ tasks.named("check") {
}
}

tasks.register("run") {
tasks.register("bootRun") {
group = mainBuildGroup
description = "Build and run as standalone application"
description = "Build and run as standalone Spring Boot application"
dependsOn(":app:$name")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@ dependencies.components {
withModule<ParentPomAsPlatformRule>(HttpComponentsPlatformRule.HTTP_COMPONENTS_CLIENT)
withModule<ParentPomAsPlatformRule>(Slf4jPlatformRule.SLF4J_PARENT)
}

configurations.all {
resolutionStrategy.capabilitiesResolution.withCapability("javax.activation:activation") {
select("com.sun.activation:jakarta.activation:0")
}
}
1 change: 1 addition & 0 deletions gradle/plugins/java-application-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ dependencies {
implementation("org.example:build-parameters-plugins")
implementation("org.owasp:dependency-check-gradle")
implementation("io.fuchs.gradle.classpath-collision-detector:classpath-collision-detector")
implementation("org.springframework.boot:spring-boot-gradle-plugin")
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import org.example.application.tasks.VersionXml

plugins {
id("org.example.java")
id("application") // For stand-alone application packaging
id("org.springframework.boot")
id("jacoco-report-aggregation") // get and aggregated coverage report for all tests
id("test-report-aggregation") // get and aggregated result report for all tests
id("org.example.war") // For web application packaging/deployment
Expand All @@ -12,6 +12,14 @@ plugins {
id("org.owasp.dependencycheck")
}

dependencies {
developmentOnly(platform("org.example.product:platform"))
developmentOnly("org.springframework.boot:spring-boot-devtools")
}

configurations.productionRuntimeClasspath {
shouldResolveConsistentlyWith(configurations.appRuntimeClasspath.get())
}
configurations.aggregateTestReportResults {
shouldResolveConsistentlyWith(configurations.appRuntimeClasspath.get())
}
Expand All @@ -31,6 +39,7 @@ val resourcesChecksum = tasks.register<MD5DirectoryChecksum>("resourcesChecksum"
}

tasks.processResources {
from(rootProject.layout.projectDirectory.file("gradle/version.txt"))
from(generateVersionXml)
from(resourcesChecksum)
}
Expand Down
1 change: 1 addition & 0 deletions gradle/plugins/java-library-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ dependencies {
implementation(platform(project(":plugins-platform")))

implementation(project(":java-base-plugins"))
implementation("org.springframework.boot:spring-boot-gradle-plugin")
}
1 change: 1 addition & 0 deletions gradle/plugins/plugins-platform/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ dependencies.constraints {
api("io.fuchs.gradle.classpath-collision-detector:classpath-collision-detector:0.3")
api("org.gradlex:java-ecosystem-capabilities:1.3.1")
api("org.owasp:dependency-check-gradle:9.0.2")
api("org.springframework.boot:spring-boot-gradle-plugin:2.7.18")
}
4 changes: 0 additions & 4 deletions kamino/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ plugins {

dependencies {
api(project(":coruscant"))
api("org.jboss.resteasy:resteasy-core")

implementation("org.jboss.resteasy:resteasy-guice")
implementation("org.jboss.resteasy:resteasy-jackson2-provider")

testImplementation("org.junit.jupiter:junit-jupiter-api")
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
package org.example.product.kamino;

import org.example.product.coruscant.CoruscantModuleData;
import org.jboss.resteasy.plugins.guice.GuiceResteasyBootstrapServletContextListener;
import org.jboss.resteasy.plugins.providers.jackson.ResteasyJackson2Provider;
import org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap;

/**
* I am published and therefore I have Javadoc!
*/
public class KaminoModule {

/**
* Bootstrap...
*/
public ResteasyBootstrap bootstrap;

/**
* Data...
Expand All @@ -26,10 +18,6 @@ public class KaminoModule {
* @return all the important Classes
*/
public Class<?>[] info() {
return new Class[]{
ResteasyBootstrap.class,
ResteasyJackson2Provider.class,
GuiceResteasyBootstrapServletContextListener.class
};
return new Class[]{};
}
}

0 comments on commit abd84c1

Please sign in to comment.