2012-04-30 30 views
5

के साथ संयोजन में उपयोग किया जा सकता है, मैं स्प्रिंग 3.0.5 से 3.1 तक माइग्रेशन कर रहा हूं क्योंकि मुझे कस्टम RequestMappingHandlerMapping होना आवश्यक है। मुझे विस्तारित RequestMappingHandlerMapping के प्लग-इन में समस्याएं आ रही हैं - मेरे पास मौजूदा servlet-conetxt.xml था और मैंने @Configuration एनोटेशन के साथ WebConfig जोड़ा। लेकिन, मुझे हमेशा त्रुटि ambiguos मैपिंग मिलती है (क्योंकि विस्तारित RequestMappingHandlerMapping में परिभाषित नई एनोटेशन प्रभाव में नहीं है)।स्प्रिंग 3.1 में <mvc: interceptors> को @ कॉन्फ़िगरेशन

मेरे पास servlet-context.xml में परिभाषित इंटरसेप्टर के विभिन्न स्तर हैं जिन्हें मैं एक्सएमएल कॉन्फ़िगरेशन में रखना चाहता हूं। मैं उपयोग करना चाहता हूँ ।

क्या servlet-context.xml के संयोजन का उपयोग करने का एक तरीका है और साथ ही RequestMappingHandlerMapping का विस्तार करें। यदि इसे @COnfiguration का उपयोग करके किया जाना है - क्या मैं @COnfiguration और servlet-context.xml दोनों का उपयोग कर सकता हूं? किसी भी मदद की सराहना की जाएगी क्योंकि मैं लंबे समय से यह कोशिश कर रहा हूं।

<context-param> 
    <param-name>contextClass</param-name> 
    <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value> 
</context-param> 

<context-param> 
<param-name>contextConfigLocation</param-name> 
<param-value>com.test.config</param-value> 
</context-param> 

उत्तर

7

हाँ, आप इसका इस्तेमाल कर सकते हैं: उदाहरण:

@EnableWebMvc 
@Configuration 
public class WebConfig extends WebMvcConfigurerAdapter { 

    @Override 
    public void addInterceptors(InterceptorRegistry registry) { 
    registry.addInterceptor(new LocalInterceptor()); 
    registry.addInterceptor(new SecurityInterceptor()).addPathPatterns("/secure/*"); 
} 

} 

सिर्फ अधिक जानकारी के लिए

http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/mvc.html#mvc-config-interceptors को देखें।

+1

धन्यवाद डैनी के लिए सेटिंग नहीं किया जा सकता। मैं इसे काम करने के लिए @ImportResource का उपयोग करने में सक्षम था। –

0

का उपयोग करता है, तो

@EnableWebMvc 
@Configuration 
public class WebConfig extends WebMvcConfigurerAdapter { 
    @Autowired 
    Anything anything; 

    @Override 
    public void addInterceptors(InterceptorRegistry registry) { 
    log.info(anything.toString());//this will exception,how to fix? 
    registry.addInterceptor(new LocalInterceptor()); 
    registry.addInterceptor(new SecurityInterceptor()).addPathPatterns("/secure/*"); 
} 

} 

@service इंटरसेप्टर