如何将 applicationContext.xml 转换为 spring

我有这个applicationContext.xml文件,我想将其表达为弹簧@Configuration组件。我怎样才能做到这一点?Spring官方文档中有关于如何将XML配置转换为基于Java的配置的部分吗?

以下 XML 片段来自项目,它为 Spring 实现了自定义 ViewScope。为了使用它的 ViewScope 实现,我必须将此配置添加到 my 中applicationContext.xml,但我想用 Java 表达此配置。

<bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">

    <property name="scopes">

        <map>

            <entry key="view">

                <bean class="com.github.jneat.jsf.ViewScope"/>

            </entry>

        </map>

    </property>

</bean>


UYOU
浏览 142回答 2
2回答

守候你守候我

您可以尝试这个(在您指出的项目的自述文件中):import java.util.HashMap;import java.util.Map;import com.github.jneat.jsf.ViewScope;import org.springframework.beans.factory.config.CustomScopeConfigurer;import org.springframework.context.annotation.Configuration;@Configurationpublic class MyViewScope {&nbsp; &nbsp; @Bean&nbsp; &nbsp; public CustomScopeConfigurer customScopeConfigurer() {&nbsp; &nbsp; &nbsp; &nbsp; CustomScopeConfigurer configurer = new CustomScopeConfigurer();&nbsp; &nbsp; &nbsp; &nbsp; Map<String,Object> scopes = new HashMap<String,Object>();&nbsp; &nbsp; &nbsp; &nbsp; scope.put("view", new ViewScope());&nbsp; &nbsp; &nbsp; &nbsp; configurer.setScopes(scopes);&nbsp; &nbsp; &nbsp; &nbsp; return configurer;&nbsp; &nbsp; }}你也可以看看这个问题

ibeautiful

尝试这个:@Beanpublic CustomScopeConfigurer customScope(WorkflowScope viewScope) {&nbsp; &nbsp; CustomScopeConfigurer configurer = new CustomScopeConfigurer();&nbsp; &nbsp; Map<String, Object> viewScope = new HashMap<>();&nbsp; &nbsp; viewScopeSet.put("view", viewScope);&nbsp; &nbsp; configurer.setScopes(viewScopeSet);&nbsp; &nbsp; return configurer;}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java