Skip to content

Commit

Permalink
Migrate to latest Spring Boot 2.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Nonononoki committed Jul 23, 2021
1 parent 0b80187 commit f3b3935
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 40 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.9.RELEASE</version>
<version>2.5.3</version>
<relativePath />
</parent>
<groupId>com.alovoa</groupId>
Expand Down
58 changes: 26 additions & 32 deletions src/main/java/com/nonononoki/alovoa/config/WebMvcConfig.java
@@ -1,52 +1,46 @@
package com.nonononoki.alovoa.config;

import java.nio.charset.StandardCharsets;
import java.util.Locale;

import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.i18n.CookieLocaleResolver;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;

@Configuration
@EnableWebMvc
@ComponentScan
public class WebMvcConfig implements WebMvcConfigurer {


@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
}

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry
.addResourceHandler("/**")
.addResourceLocations("classpath:/static/");
}

@Bean(name = "localeResolver")
public LocaleResolver getLocaleResolver() {
CookieLocaleResolver clr = new CookieLocaleResolver();
clr.setDefaultLocale(Locale.ENGLISH);
return clr;
}

@Bean(name = "messageSource")
public MessageSource getMessageResource() {
ReloadableResourceBundleMessageSource messageResource= new ReloadableResourceBundleMessageSource();
messageResource.setBasename("classpath:i18n/messages");
messageResource.setDefaultEncoding(StandardCharsets.UTF_8.name());
return messageResource;
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
LocaleChangeInterceptor localeInterceptor = new LocaleChangeInterceptor();
localeInterceptor.setParamName("lang");
registry.addInterceptor(localeInterceptor).addPathPatterns("/*");
}

public void addInterceptors(InterceptorRegistry registry) {
LocaleChangeInterceptor localeInterceptor = new LocaleChangeInterceptor();
localeInterceptor.setParamName("lang");
registry.addInterceptor(localeInterceptor).addPathPatterns("/*");
}

@Bean
public CookieLocaleResolver localeResolver() {
return new CookieLocaleResolver();
}

@Bean
public ReloadableResourceBundleMessageSource messageSource() {
ReloadableResourceBundleMessageSource messageResource = new ReloadableResourceBundleMessageSource();
messageResource.setBasename("classpath:i18n/messages");
messageResource.setDefaultEncoding(StandardCharsets.UTF_8.name());
return messageResource;
}

}
9 changes: 4 additions & 5 deletions src/main/java/com/nonononoki/alovoa/service/UserService.java
Expand Up @@ -547,9 +547,8 @@ public void addImage(String imgB64) throws AlovoaException, IOException {

public void deleteImage(long id) throws AlovoaException {
User user = authService.getCurrentUser();
UserImage img = userImageRepo.getOne(id);

if (user.getImages().contains(img)) {
UserImage img = userImageRepo.findById(id).orElse(null);
if (img != null && user.getImages().contains(img)) {
user.getImages().remove(img);
userRepo.saveAndFlush(user);
}
Expand Down Expand Up @@ -667,9 +666,9 @@ public void likeUser(String idEnc) throws AlovoaException, GeneralSecurityExcept
notificationService.newLike(user);

user.getDates().setNotificationDate(new Date());

currUser.getHiddenUsers().removeIf(hide -> hide.getUserTo().getId().equals(user.getId()));

userRepo.saveAndFlush(user);
userRepo.saveAndFlush(currUser);

Expand Down
6 changes: 4 additions & 2 deletions src/main/resources/application.properties
Expand Up @@ -9,9 +9,11 @@ server.port=${PORT:8443}
#server.ssl.key-store-password=alovoa
#server.ssl.key-alias=alovoa

spring.main.allow-bean-definition-overriding=true

server.http2.enabled=true

spring.datasource.platform=mysql
spring.sql.init.platform=mysql
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/alovoa?createDatabaseIfNotExist=true&serverTimezone=UTC&useLegacyDatetimeCode=false

Expand All @@ -23,7 +25,7 @@ spring.datasource.url=jdbc:mysql://localhost:3306/alovoa?createDatabaseIfNotExis

#we keep the default /login/oauth2/code/{registrationId} scheme

spring.mvc.locale=en_EN
spring.web.locale=en_EN

spring.security.oauth2.client.registration.google.scope[0]=email
spring.security.oauth2.client.registration.google.scope[1]=profile
Expand Down

0 comments on commit f3b3935

Please sign in to comment.