-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove spring-boot-starter-web dependency, add webflux example
By removing the dependency on spring-boot-starter-web, we make it easier to utilize in a webflux application. The added webflux example shows how to add a router function to serve the static assets.
- Loading branch information
1 parent
5f5b7cb
commit 8b33af4
Showing
25 changed files
with
912 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Use the official OpenJDK base image | ||
FROM openjdk:11-jdk-slim | ||
|
||
# Set the working directory inside the container | ||
WORKDIR /app | ||
|
||
COPY ./*.jar /app/app.jar | ||
|
||
EXPOSE 8081 | ||
|
||
# Command to run the application | ||
CMD ["java", "-jar", "/app/app.jar"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
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>no.bekk.db-scheduler-ui</groupId> | ||
<artifactId>db-scheduler-ui-parent</artifactId> | ||
<version>main-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>example-app-webflux</artifactId> | ||
<name>example-app-webflux</name> | ||
<description>Example app using db-scheduler-ui and WebFlux</description> | ||
|
||
<properties> | ||
<maven.deploy.skip>true</maven.deploy.skip> | ||
</properties> | ||
|
||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-webflux</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-jdbc</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-devtools</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
<version>2.2.220</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.flywaydb</groupId> | ||
<artifactId>flyway-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-actuator</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.rocketbase.extension</groupId> | ||
<artifactId>db-scheduler-log-spring-boot-starter</artifactId> | ||
<version>0.7.0</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.assertj</groupId> | ||
<artifactId>assertj-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.hsqldb</groupId> | ||
<artifactId>hsqldb</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>no.bekk.db-scheduler-ui</groupId> | ||
<artifactId>db-scheduler-ui-starter</artifactId> | ||
<version>main-SNAPSHOT</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<version>${spring-boot.version}</version> | ||
<configuration> | ||
<mainClass>com.github.bekk.exampleapp.ExampleAppWebFlux</mainClass> | ||
<layout>JAR</layout> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>repackage</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
37 changes: 37 additions & 0 deletions
37
example-app-webflux/src/main/java/com/github/bekk/exampleapp/ExampleAppWebFlux.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (C) Bekk | ||
* | ||
* <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file | ||
* except in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* <p>http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* <p>Unless required by applicable law or agreed to in writing, software distributed under the | ||
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.github.bekk.exampleapp; | ||
|
||
import com.github.bekk.exampleapp.service.TaskService; | ||
import com.github.kagkarlsson.scheduler.Scheduler; | ||
import org.springframework.boot.CommandLineRunner; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
@SpringBootApplication | ||
public class ExampleAppWebFlux { | ||
public static void main(String[] args) { | ||
SpringApplication.run(ExampleAppWebFlux.class, args); | ||
} | ||
|
||
@Bean | ||
public CommandLineRunner runAllManuallyTriggeredTasks(Scheduler scheduler) { | ||
return args -> { | ||
System.out.println("Running all manually triggered tasks"); | ||
TaskService taskService = new TaskService(scheduler); | ||
taskService.runManuallyTriggeredTasks(); | ||
}; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
example-app-webflux/src/main/java/com/github/bekk/exampleapp/config/DatabaseConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (C) Bekk | ||
* | ||
* <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file | ||
* except in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* <p>http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* <p>Unless required by applicable law or agreed to in writing, software distributed under the | ||
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.github.bekk.exampleapp.config; | ||
|
||
import javax.sql.DataSource; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; | ||
import org.springframework.jdbc.core.simple.SimpleJdbcInsert; | ||
|
||
@Configuration | ||
public class DatabaseConfig { | ||
private final DataSource dataSource; | ||
|
||
public DatabaseConfig(DataSource dataSource) { | ||
this.dataSource = dataSource; | ||
} | ||
|
||
@Bean | ||
public JdbcTemplate jdbcTemplate() { | ||
return new JdbcTemplate(dataSource); | ||
} | ||
|
||
@Bean | ||
public SimpleJdbcInsert simpleJdbcInsert() { | ||
return new SimpleJdbcInsert(dataSource) | ||
.withTableName("scheduled_tasks") | ||
.usingGeneratedKeyColumns("id"); | ||
} | ||
|
||
@Bean | ||
public NamedParameterJdbcTemplate namedParameterJdbcTemplate() { | ||
return new NamedParameterJdbcTemplate(dataSource); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
example-app-webflux/src/main/java/com/github/bekk/exampleapp/config/SchedulerConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright (C) Bekk | ||
* | ||
* <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file | ||
* except in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* <p>http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* <p>Unless required by applicable law or agreed to in writing, software distributed under the | ||
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.github.bekk.exampleapp.config; | ||
|
||
import com.github.kagkarlsson.scheduler.serializer.JavaSerializer; | ||
import io.rocketbase.extension.jdbc.JdbcLogRepository; | ||
import io.rocketbase.extension.jdbc.Snowflake; | ||
import javax.sql.DataSource; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class SchedulerConfig { | ||
private final DataSource dataSource; | ||
|
||
@Autowired | ||
public SchedulerConfig(DataSource dataSource) { | ||
this.dataSource = dataSource; | ||
} | ||
|
||
@Bean | ||
public JdbcLogRepository jdbcLogRepository() { | ||
return new JdbcLogRepository( | ||
dataSource, new JavaSerializer(), JdbcLogRepository.DEFAULT_TABLE_NAME, new Snowflake()); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
example-app-webflux/src/main/java/com/github/bekk/exampleapp/config/WebConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (C) Bekk | ||
* | ||
* <p>Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file | ||
* except in compliance with the License. You may obtain a copy of the License at | ||
* | ||
* <p>http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* <p>Unless required by applicable law or agreed to in writing, software distributed under the | ||
* License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.github.bekk.exampleapp.config; | ||
|
||
import static org.springframework.web.reactive.function.server.RequestPredicates.GET; | ||
import static org.springframework.web.reactive.function.server.RouterFunctions.route; | ||
import static org.springframework.web.reactive.function.server.ServerResponse.ok; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.web.reactive.function.server.RouterFunction; | ||
import org.springframework.web.reactive.function.server.ServerResponse; | ||
|
||
@Configuration | ||
public class WebConfig { | ||
@Bean | ||
public RouterFunction<ServerResponse> dbSchedulerRouter( | ||
@Value("classpath:/static/db-scheduler-ui/index.html") final Resource indexHtml) { | ||
return route( | ||
GET("/db-scheduler/**"), | ||
request -> ok().contentType(MediaType.TEXT_HTML).bodyValue(indexHtml)); | ||
} | ||
} |
Oops, something went wrong.