Notice
		                                        
										
                                    
                                        
                                    
                                        Recent Posts
                                        
                                    
                                        
                                    
                                        Recent Comments
                                        
                                    
                                        
                                    
                                        Link
                                        
                                    
                                | 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 | 
| 9 | 10 | 11 | 12 | 13 | 14 | 15 | 
| 16 | 17 | 18 | 19 | 20 | 21 | 22 | 
| 23 | 24 | 25 | 26 | 27 | 28 | 29 | 
| 30 | 
                                        Tags
                                        
                                    
                                        
                                    - SQL
 - GIT
 - JavaScript
 - Sqoop
 - 보조정렬
 - plugin
 - MSSQL
 - Kotlin
 - 공정능력
 - NPM
 - mapreduce
 - Express
 - hadoop
 - tomcat
 - Java
 - Eclipse
 - vaadin
 - window
 - SSL
 - Android
 - xPlatform
 - IntelliJ
 - SPC
 - react
 - table
 - R
 - mybatis
 - Spring
 - Python
 - es6
 
                                        Archives
                                        
                                    
                                        
                                    - Today
 
- Total
 
DBILITY
spring boot rest api cors 본문
반응형
    
    
    
  간단하게 허용하고 싶은 request mapping에 annotation으로 처리해 보았다.
개발 중인 react app가 3000번 포트에서 실행 중이고, springboot rest api는 9090으로 운영 중에 요청 처리를 한 것이다.
서버 쪽에서 허용을 해주는 것이므로, 요청하는 app의 경로를 적어 주면 되나 보다.
package com.dbility.apps.dev.test;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
@Slf4j
@RestController
public class RoomsController {
    @Resource(name="roomsService")
    private RoomsService roomsService;
    @CrossOrigin(origins = "http://localhost:3000")
    @GetMapping(value = "/findall")
    public List<RoomsEntity> getRooms() throws Exception {
        return roomsService.findAll();
    }
}
전체에 대한 설정은 appconfig에서 하면 되겠지?
다음과 같이 해봤다.
package com.dbility.apps.dev.test;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedMethods("GET","POST")
                .allowedOrigins("http://localhost:3000")
                .allowCredentials(true);
    }
}반응형
    
    
    
  'java > spring boot' 카테고리의 다른 글
| spring boot embedded tomcat docroot change (0) | 2022.02.24 | 
|---|---|
| maven Blocked mirror for repositories~ (0) | 2022.02.19 | 
| spring data jpa study code (0) | 2022.02.18 | 
                          Comments
                        
                    
                
            
                
            
				
				
				
				
                
							