为了账号安全,请及时绑定邮箱和手机立即绑定

如何将 applicationContext.xml 转换为 spring

如何将 applicationContext.xml 转换为 spring

UYOU 2024-01-05 16:45:29
我有这个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>
查看完整描述

2 回答

?
守候你守候我

TA贡献1802条经验 获得超10个赞

您可以尝试这个(在您指出的项目的自述文件中):

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;


@Configuration

public class MyViewScope {


    @Bean

    public CustomScopeConfigurer customScopeConfigurer() {

        CustomScopeConfigurer configurer = new CustomScopeConfigurer();


        Map<String,Object> scopes = new HashMap<String,Object>();

        scope.put("view", new ViewScope());


        configurer.setScopes(scopes);

        return configurer;

    }

}

你也可以看看这个问题


查看完整回答
反对 回复 2024-01-05
?
ibeautiful

TA贡献1993条经验 获得超5个赞

尝试这个:


@Bean

public CustomScopeConfigurer customScope(WorkflowScope viewScope) {

    CustomScopeConfigurer configurer = new CustomScopeConfigurer();

    Map<String, Object> viewScope = new HashMap<>();


    viewScopeSet.put("view", viewScope);

    configurer.setScopes(viewScopeSet);


    return configurer;

}


查看完整回答
反对 回复 2024-01-05
  • 2 回答
  • 0 关注
  • 61 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信