Register converters and converterFactories with annotations in Spring 3

前端 未结 7 1421
没有蜡笔的小新
没有蜡笔的小新 2020-12-09 21:11

First of all ... Im relatively new in Spring, I use spring 3.x and I DONT LIKE SPRING\'S XML CONFIGURATION FILES ... I dont want for every refactoring I do, to run into XML

7条回答
  •  天涯浪人
    2020-12-09 21:51

    With Spring MVC 3.2, you can create a conversion service class that extends the DefaultFormattingConversionService e.g

    ApplicationConversionService.java

    import org.springframework.format.support.DefaultFormattingConversionService;
    import org.springframework.stereotype.Component;
    
    @Component("conversionService")
    public class ApplicationConversionService extends DefaultFormattingConversionService  { 
    
        public ApplicationConversionService(){
            //DefaultFormattingConversionService's default constructor
            //creates default formatters and converters
            super(); //no need for explicit super()?
    
            //add custom formatters and converters
            addConverter(new MyConverter());
        }
    
    }
    

    and specify it in the spring config e.g

    dispatcher-servlet.xml

    
    

提交回复
热议问题