gpt4 book ai didi

java - java类JAVA中的Spring xml配置重写

转载 作者:太空宇宙 更新时间:2023-11-04 12:37:22 25 4
gpt4 key购买 nike

如何在我的应用程序中使用的 Java .class @Bean 文件中重写此 xml 配置。

<bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/welcome.htm">welcomeController</prop>
</props>
</property>
<property name="interceptors">
<list>
<ref bean="maintenanceInterceptor" />
<ref bean="executeTimeInterceptor" />
</list>
</property>
</bean>

<bean
class="org.springframework.web.servlet.mvc.support.ControllerClassNameHandlerMapping">
<property name="interceptors">
<list>
<ref bean="executeTimeInterceptor" />
</list>
</property>
</bean>

最佳答案

@Bean public SimpleUrlHandlerMapping simpleURLHandlerMapping() {
SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
mapping.setOrder(Integer.MAX_VALUE - 2);

Properties urlProperties = new Properties();
urlProperties.put("/welcome.htm", "welcomeController");

mapping.setMappings(urlProperties);
mapping.setInterceptors(new Object[]{ maintenanceInterceptor(), executeTimeInterceptor() });

return mapping; }

关于java - java类JAVA中的Spring xml配置重写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37181679/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com