최초 세팅
This commit is contained in:
46
src/main/java/com/madeu/config/DatabaseConfig.java
Normal file
46
src/main/java/com/madeu/config/DatabaseConfig.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package com.madeu.config;
|
||||
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.mybatis.spring.SqlSessionFactoryBean;
|
||||
import org.mybatis.spring.SqlSessionTemplate;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.jdbc.DataSourceBuilder;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
@Configuration
|
||||
public class DatabaseConfig {
|
||||
|
||||
@Bean
|
||||
@ConfigurationProperties(prefix = "spring.datasource.hikari")
|
||||
public DataSource dataSource(){
|
||||
return DataSourceBuilder.create()
|
||||
.type(HikariDataSource.class)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SqlSessionFactory sqlSessionFactory(DataSource dataSource, ApplicationContext applicationContext) throws Exception{
|
||||
SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
|
||||
factoryBean.setDataSource(dataSource);
|
||||
factoryBean.setMapperLocations(applicationContext.getResources("classpath:/mappers/**/*.xml"));
|
||||
|
||||
return factoryBean.getObject();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory){
|
||||
return new SqlSessionTemplate(sqlSessionFactory);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataSourceTransactionManager transactionManager(DataSource dataSource) {
|
||||
return new DataSourceTransactionManager(dataSource);
|
||||
}
|
||||
|
||||
}
|
||||
22
src/main/java/com/madeu/config/SchedulerConfig.java
Normal file
22
src/main/java/com/madeu/config/SchedulerConfig.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package com.madeu.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.SchedulingConfigurer;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
|
||||
@Configuration
|
||||
public class SchedulerConfig implements SchedulingConfigurer {
|
||||
private final int POOL_SIZE = 10;
|
||||
|
||||
@Override
|
||||
public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
|
||||
ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
|
||||
|
||||
threadPoolTaskScheduler.setPoolSize(POOL_SIZE);
|
||||
threadPoolTaskScheduler.setThreadNamePrefix("my-scheduled-task-pool-");
|
||||
threadPoolTaskScheduler.initialize();
|
||||
|
||||
scheduledTaskRegistrar.setTaskScheduler(threadPoolTaskScheduler);
|
||||
}
|
||||
}
|
||||
14
src/main/java/com/madeu/config/ThymeleafLayoutConfig.java
Normal file
14
src/main/java/com/madeu/config/ThymeleafLayoutConfig.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.madeu.config;
|
||||
|
||||
import nz.net.ultraq.thymeleaf.layoutdialect.LayoutDialect;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class ThymeleafLayoutConfig {
|
||||
|
||||
@Bean
|
||||
public LayoutDialect layoutDialect() {
|
||||
return new LayoutDialect();
|
||||
}
|
||||
}
|
||||
54
src/main/java/com/madeu/config/WebConfig.java
Normal file
54
src/main/java/com/madeu/config/WebConfig.java
Normal file
@@ -0,0 +1,54 @@
|
||||
package com.madeu.config;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
import org.springframework.web.servlet.resource.PathResourceResolver;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Configuration
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
@Value("${file.upload-path}")
|
||||
private String uploadPath;
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/cdn/**")
|
||||
.addResourceLocations("file:" + uploadPath + "/")
|
||||
.setCachePeriod(3600) // 1시간 캐싱
|
||||
.resourceChain(true)
|
||||
.addResolver(new PathResourceResolver() {
|
||||
@Override
|
||||
protected Resource getResource(String resourcePath, Resource location) throws IOException {
|
||||
Resource requestedResource = location.createRelative(resourcePath);
|
||||
|
||||
// 보안 검증: 허용된 파일 타입만
|
||||
if (requestedResource.exists() && requestedResource.isReadable()
|
||||
&& isAllowedResource(requestedResource)) {
|
||||
return requestedResource;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean isAllowedResource(Resource resource) {
|
||||
try {
|
||||
String filename = resource.getFilename();
|
||||
return filename != null &&
|
||||
(filename.toLowerCase().endsWith(".jpg") ||
|
||||
filename.toLowerCase().endsWith(".jpeg") ||
|
||||
filename.toLowerCase().endsWith(".png") ||
|
||||
filename.toLowerCase().endsWith(".gif") ||
|
||||
filename.toLowerCase().endsWith(".webp") ||
|
||||
filename.toLowerCase().endsWith(".bmp") ||
|
||||
filename.toLowerCase().endsWith(".svg"));
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user