Close

Spring MVC - @Configuration Examples

Spring MVC 

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

@Configuration
@EnableWebMvc
public class MyViewConfig{
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setPrefix("/WEB-INF/views/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
}
Original Post




import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@EnableWebMvc
@Configuration
@Import(MyViewConfig.class)
public class TradeConfig extends WebMvcConfigurerAdapter {

@Bean
public TradeController tradeParamRequestController() {
return new TradeController();
}

@Bean
public TradeService tradeService(){
return new TradeService();
}


@Override
public void addFormatters (FormatterRegistry registry) {
registry.addConverter(new TradeIdToTradeConverter(tradeService()));
}

}
Original Post




See Also