Framework/Spring Boot

Configuration error (css, js 파일이 Servlet을 타서 발생하는 오류)

반응형

입사 후 과제를 하던 도중 css파일에 대한 mapping이 없다는 오류가 자꾸 뜨기 시작했다. Spring Security와 interceptor 설정을 하다가 발생했다. 로그인 인터셉터를 설정하고 싶었는데... 아래 컨피그 클래스 소스에서 Configuration Annotation을 지우면 문제 없이 돌아가지만 인터셉터가 작동하지 않고, 반대의 경우엔 인터셉터를 포기하고 css를 정상적으로 읽어오는 상황.

@Configuration
public class CustomWebMvcConfigurer extends WebMvcConfigurationSupport {

    @Override //로그인 인터셉터..
    protected void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptor())
                .addPathPatterns("/view/**")
                .excludePathPatterns("/css/**");
    }
    
    /*    //리소스핸들러..
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry
                .addResourceHandler("/resources/**")
                .addResourceLocations("/resources/");
    }*/
}

▲ 컨피그 클래스

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {
        httpSecurity.httpBasic().disable();
    }
}

▲ 스프링 시큐리티 컨피그 클래스. 이것도 쓰려다 제대로 사용하지 못해서 롤백시켰었음. 

spring.datasource.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://27.96.135.114:5432/train_db
spring.datasource.username=train_user
spring.datasource.password=1234

mybatis.type-aliases-package=com.planit.assign5.domain
mybatis.config-location=classpath:mybatis-config.xml
mybatis.mapper-locations=classpath:com.planit.assign5/mapper/*.xml

pagehelper.helper-dialect=postgresql
pagehelper.reasonable=true

▲ application.properties 파일. 

plugins {
    id 'org.springframework.boot' version '2.4.5'
    id 'io.spring.dependency-management' version '1.0.11.RELEASE'
    id 'java'
}

group = 'com.planit'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.1.4'
    runtimeOnly 'org.postgresql:postgresql'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'

    //thymeleaf
    implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
    implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'
    implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5'

    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.security:spring-security-test'
    implementation 'org.thymeleaf.extras:thymeleaf-extras-springsecurity5'

    implementation 'org.webjars:jquery:3.5.0'
    implementation 'org.webjars:jquery-ui:1.12.1'

    //lombok
    implementation 'org.projectlombok:lombok'
    compileOnly 'org.projectlombok:lombok'
    annotationProcessor 'org.projectlombok:lombok'

    //paging
    compile group: 'com.github.pagehelper', name: 'pagehelper-spring-boot-starter', version:'1.2.7'
}

test {
    useJUnitPlatform()
}

▲ build.gradle 파일. 

아마 설정파일들이 서로 꼬여서 문제가 생긴 것 같은데 결국 해결하지 못했다. 나중에 다시 들여다보기 위해 기록을 남겨둔다.

728x90
반응형