如何在applicationContext-security.xml中定义bean /资源@Resource(mappedName =“ abc / xyz / mnop”)?

时间:2018-12-13 10:08:41

标签: java spring

我有一个要求,我们要将所有JNDI配置移到bean。在上下文占位符中,我们将放置标签并在服务器秘密位置中配置值。这样,我们就不必为每个服务器/域编写Tomcat context.xml。

现在的问题是: 我有代码:

@Resource(mappedName = "abc/xyz/mnop")
    private String mnop_id;

@Bean
    public String mnop_id() {
        return mnop_id;
    }

如果我放置<Environment name="abc/xyz/mnop" override="false" type="java.lang.String" value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" /> 在Tomcat context.xml中,它可以工作。 但我想做这样的事情:

<beans:bean id="abc/xyz/mnop" class="java.lang.String">
                <constructor-arg value="com.aaa.service.val"/>
            </beans:bean>

我遇到错误:

ERROR o.s.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sessionFilter' defined in file [/usr/local/tomcat/webapps/portal/WEB-INF/classes/META-INF/spring/applicationContext-security.xml]: Unsatisfied dependency expressed through constructor argument with index 1 of type [com.aaa.service.cloud.common.SessionRetrievalStrategy]: : Error creating bean with name 'securityConfig': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'abc/xyz/mnop' is defined: not found in JNDI environment; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityConfig': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'abc/xyz/mnop' is defined: not found in JNDI environment

securityConfig是我的类构造函数 我在里面定义bean:

<beans:bean id="sessionFilter" class="com.aaa.service.cloud.common.SessionRetrievalStrategy">

请帮助。 预先感谢。

0 个答案:

没有答案