I am transferring my spring mvc application to spring boot application. I am also transferring my xml base configuration to class based.
I have done most of thing running. I just dont know that how to scan REST controller package. Beans are creating, but REST controller beans is not creating.
Which annotation is used ? At where to give configuration to scan for controller. Still don't know.
In XML I have tag :
<context:component-scan base-package="ApiServer" />
Now how to convert it into simple class configuration i don't know. Controller :
@Controller
@RequestMapping(value = SeriesController.BASE_URL)
public class SeriesController {
public static final String BASE_URL = "/setup/series";
@RequestMapping(method = RequestMethod.GET)
public @ResponseBody
ResponseEntity<List<SeriesResponse>> getSeries(){
List<SeriesResponse> responses = new ArrayList<>();
return new ResponseEntity<>(responses, HttpStatus.OK);
}
}
Main Class :
@SpringBootApplication
public class Application {
public static void main(String[] args) throws Exception {
ApplicationContext ctx = SpringApplication.run(Application.class, args);
String[] beanNames = ctx.getBeanDefinitionNames();
Arrays.sort(beanNames);
for (String beanName : beanNames) {
System.out.println("BEAN :: " + beanName);
}
}
@Bean
public FilterRegistrationBean filterRegistrationBean() {
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
CORSFilter corsFilter = new CORSFilter();
registrationBean.setFilter(corsFilter);
registrationBean.setOrder(1);
return registrationBean;
}
}
Aucun commentaire:
Enregistrer un commentaire