Skip to content

Commit

Permalink
Upgrade to Spring Boot 3 (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
fcrespel committed Dec 27, 2023
1 parent f58aa4e commit 4fe05f4
Show file tree
Hide file tree
Showing 24 changed files with 202 additions and 256 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up JDK 11
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '11'
java-version: '17'
distribution: temurin
cache: maven
settings-path: ${{ github.workspace }}/.mvn
Expand Down
40 changes: 12 additions & 28 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.18</version>
<version>3.1.7</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

Expand All @@ -19,7 +19,7 @@

<properties>
<!-- Project properties -->
<java.version>11</java.version>
<java.version>17</java.version>
<start-class>me.crespel.karaplan.KaraplanApplication</start-class>
<nodejs.src.directory>${basedir}/src/main/nodejs</nodejs.src.directory>
<nodejs.build.directory>${project.build.directory}/nodejs</nodejs.build.directory>
Expand All @@ -44,8 +44,8 @@
<node.version>v18.19.0</node.version>
<npm.version>10.2.3</npm.version>
<socketio-client.version>1.0.1</socketio-client.version>
<spring-cloud-gcp.version>3.7.4</spring-cloud-gcp.version>
<springdoc.version>1.7.0</springdoc.version>
<spring-cloud-gcp.version>4.9.0</spring-cloud-gcp.version>
<springdoc.version>2.3.0</springdoc.version>
</properties>

<scm>
Expand Down Expand Up @@ -86,14 +86,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
Expand Down Expand Up @@ -129,17 +121,13 @@
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-data-redis</artifactId>
<artifactId>spring-session-jdbc</artifactId>
</dependency>

<!-- Springdoc OpenAPI -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-security</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
</dependency>

<!-- Utilities -->
Expand All @@ -148,8 +136,9 @@
<artifactId>commons-csv</artifactId>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<classifier>jakarta</classifier>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
Expand All @@ -161,7 +150,7 @@
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-hibernate5</artifactId>
<artifactId>jackson-datatype-hibernate6</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
Expand Down Expand Up @@ -236,12 +225,7 @@
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-security</artifactId>
<version>${springdoc.version}</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>${springdoc.version}</version>
</dependency>
</dependencies>
Expand All @@ -262,8 +246,8 @@
</executions>
</plugin>
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<groupId>io.github.git-commit-id</groupId>
<artifactId>git-commit-id-maven-plugin</artifactId>
<configuration>
<failOnNoGitDirectory>false</failOnNoGitDirectory>
</configuration>
Expand Down
8 changes: 2 additions & 6 deletions src/main/appengine/app.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
runtime: java11
runtime: java17
instance_class: F4
entrypoint: java -jar karaplan-thin.jar
handlers:
Expand All @@ -20,7 +20,7 @@ handlers:
secure: always
script: auto
env_variables:
JAVA_TOOL_OPTIONS: "-XX:MaxRAM=1024m -Xms512m -Xmx512m -Xverify:none -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -agentpath:/opt/cdbg/cdbg_java_agent.so=--log_dir=/var/log"
JAVA_TOOL_OPTIONS: "-XX:MaxRAM=1024m -Xms512m -Xmx512m -Xverify:none -XX:+TieredCompilation -XX:TieredStopAtLevel=1"
SPRING_PROFILES_ACTIVE: "gcp,appengine"
automatic_scaling:
min_instances: 0
Expand All @@ -34,7 +34,3 @@ automatic_scaling:
target_cpu_utilization: 0.9
inbound_services:
- warmup
# Uncomment and configure the following block to allow access to VPC resources such as Memorystore (Redis)
# See: https://cloud.google.com/vpc/docs/configure-serverless-vpc-access
#vpc_access_connector:
# name: "projects/<project-id>/locations/<region>/connectors/<connector>"
10 changes: 0 additions & 10 deletions src/main/appengine/files/application.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ spring:
username: karaplan
password: "toComplete"
url: "jdbc:mysql:///karaplan?useSSL=false&socketFactory=com.google.cloud.sql.mysql.SocketFactory&cloudSqlInstance=toComplete"
jpa:
database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
security:
oauth2:
client:
Expand All @@ -18,11 +16,3 @@ spring:
facebook:
client-id: "toComplete"
client-secret: "toComplete"
session:
store-type: redis
redis:
configure-action: none
redis:
host: "toComplete"
server:
port: ${PORT}
3 changes: 1 addition & 2 deletions src/main/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
FROM eclipse-temurin:11-jre
FROM eclipse-temurin:17-jre
WORKDIR @docker.app.directory@
VOLUME /tmp

# Copy files
COPY WEB-INF/lib ./lib
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/me/crespel/karaplan/config/CacheConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.io.Serializable;
import java.lang.reflect.Method;

import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.cache.annotation.CachingConfigurer;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.cache.interceptor.SimpleKeyGenerator;
Expand All @@ -12,7 +12,7 @@

@Configuration
@EnableCaching
public class CacheConfig extends CachingConfigurerSupport {
public class CacheConfig implements CachingConfigurer {

@Bean
public KeyGenerator keyGenerator() {
Expand All @@ -23,31 +23,31 @@ public static class MethodAndArgsKeyGenerator implements KeyGenerator {

@Override
public Object generate(Object target, Method method, Object... params) {
return new MethodAndArgsKey(method, SimpleKeyGenerator.generateKey(params));
return new MethodAndArgsKey(method.toString(), SimpleKeyGenerator.generateKey(params));
}

}

public static class MethodAndArgsKey implements Serializable {

private Method method;
private String methodKey;
private Object paramsKey;

public MethodAndArgsKey(Method method, Object paramsKey) {
this.method = method;
public MethodAndArgsKey(String methodKey, Object paramsKey) {
this.methodKey = methodKey;
this.paramsKey = paramsKey;
}

@Override
public boolean equals(Object other) {
return this == other || (other instanceof MethodAndArgsKey &&
this.method.equals(((MethodAndArgsKey)other).method) &&
this.methodKey.equals(((MethodAndArgsKey)other).methodKey) &&
this.paramsKey.equals(((MethodAndArgsKey)other).paramsKey));
}

@Override
public int hashCode() {
return 31 * method.hashCode() + paramsKey.hashCode();
return 31 * methodKey.hashCode() + paramsKey.hashCode();
}

}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/me/crespel/karaplan/config/JacksonConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.datatype.hibernate5.Hibernate5Module;
import com.fasterxml.jackson.datatype.hibernate6.Hibernate6Module;

@Configuration
public class JacksonConfig {
Expand All @@ -25,8 +25,8 @@ public Module simpleModule() {

@Bean
public Module hibernateModule() {
Hibernate5Module module = new Hibernate5Module();
module.disable(Hibernate5Module.Feature.USE_TRANSIENT_ANNOTATION);
Hibernate6Module module = new Hibernate6Module();
module.disable(Hibernate6Module.Feature.USE_TRANSIENT_ANNOTATION);
return module;
}

Expand Down
44 changes: 20 additions & 24 deletions src/main/java/me/crespel/karaplan/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.springframework.security.oauth2.server.resource.web.BearerTokenAuthenticationEntryPoint;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
import org.springframework.security.web.csrf.CsrfTokenRequestAttributeHandler;
import org.springframework.security.web.firewall.HttpFirewall;
import org.springframework.security.web.firewall.StrictHttpFirewall;
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
Expand All @@ -25,34 +26,29 @@ public class SecurityConfig {

@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
CsrfTokenRequestAttributeHandler csrfHandler = new CsrfTokenRequestAttributeHandler();
csrfHandler.setCsrfRequestAttributeName(null); // Force loading CSRF token on every request
return http
.authorizeRequests()
.antMatchers("/", "/home").permitAll()
.antMatchers("/**/*.css", "/**/*.js", "/**/*.js.map", "/**/*.jpg", "/**/*.png", "/**/*.svg", "/**/*.ico", "/webjars/**", "/site.webmanifest", "/browserconfig.xml").permitAll()
.antMatchers("/api", "/v*/api-docs/**", "/swagger-resources/**", "/swagger-ui/**", "/csrf").permitAll()
.antMatchers("/api/v1/account/**").permitAll()
.antMatchers("/actuator/health", "/actuator/health/liveness", "/actuator/health/readiness", "/actuator/info").permitAll()
.antMatchers("/actuator/**").hasRole("ADMIN")
.antMatchers("/login").permitAll()
.antMatchers("/_ah/**").permitAll()
.anyRequest().authenticated()
.and()
.csrf()
.authorizeHttpRequests(requests -> requests
.requestMatchers("/", "/home").permitAll()
.requestMatchers("/*.css", "/*.js", "/*.js.map", "/*.jpg", "/*.png", "/*.svg", "/*.ico", "/assets/**", "/webjars/**", "/site.webmanifest", "/browserconfig.xml").permitAll()
.requestMatchers("/api", "/v3/api-docs/**", "/swagger-resources/**", "/swagger-ui/**", "/csrf").permitAll()
.requestMatchers("/api/v1/account/**").permitAll()
.requestMatchers("/actuator/health", "/actuator/health/liveness", "/actuator/health/readiness", "/actuator/info").permitAll()
.requestMatchers("/actuator/**").hasRole("ADMIN")
.requestMatchers("/login").permitAll()
.requestMatchers("/_ah/**").permitAll()
.anyRequest().authenticated())
.csrf(csrf -> csrf
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
.and()
.logout()
.deleteCookies("JSESSIONID")
.and()
.oauth2Login()
.csrfTokenRequestHandler(csrfHandler))
.oauth2Login(login -> login
.loginPage("/login")
.userInfoEndpoint()
.userInfoEndpoint(userinfo -> userinfo
.userService(oauth2UserService())
.oidcUserService(oidcUserService())
.and()
.and()
.exceptionHandling()
.defaultAuthenticationEntryPointFor(new BearerTokenAuthenticationEntryPoint(), new AntPathRequestMatcher("/api/**"))
.and()
.oidcUserService(oidcUserService())))
.exceptionHandling(handling -> handling
.defaultAuthenticationEntryPointFor(new BearerTokenAuthenticationEntryPoint(), new AntPathRequestMatcher("/api/**")))
.build();
}

Expand Down
20 changes: 10 additions & 10 deletions src/main/java/me/crespel/karaplan/domain/Artist.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
import java.util.Comparator;
import java.util.SortedSet;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;
import jakarta.validation.constraints.NotNull;

import org.hibernate.annotations.SortComparator;
import org.springframework.data.annotation.CreatedDate;
Expand Down
32 changes: 16 additions & 16 deletions src/main/java/me/crespel/karaplan/domain/Playlist.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
import java.util.Set;
import java.util.SortedSet;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.validation.constraints.NotNull;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EntityListeners;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.JoinTable;
import jakarta.persistence.ManyToMany;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.Temporal;
import jakarta.persistence.TemporalType;
import jakarta.validation.constraints.NotNull;

import org.hibernate.annotations.SortComparator;
import org.springframework.data.annotation.CreatedBy;
Expand Down
Loading

0 comments on commit 4fe05f4

Please sign in to comment.