java - Spring XML 错误 : Could not resolve placeholder 'cas.server.host'

标签 java spring spring-security spring-webflow

我正在尝试设置我的 Spring CAS.XML 文件,但我不知道为什么该文件看不到我在文件中设置的值:

谁能告诉我我遇到的以下错误是什么:

2012-09-10 11:16:00,396 ERROR org.springframework.web.context.ContextLoader - Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'requestSingleLogoutFilter' defined in ServletContext resource [/WEB-INF/spring/CAS-Local.xml]: Could not resolve placeholder 'cas.server.host'
    at org.springframework.beans.factory.config.PlaceholderConfigurerSupport.doProcessProperties(PlaceholderConfigurerSupport.java:209)

如果你看我确实在文件末尾设置了值...

这是我的 CAS-Local.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jdbc="http://www.springframework.org/schema/jdbc"
    xmlns:security="http://www.springframework.org/schema/security"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:util="http://www.springframework.org/schema/util"

    xsi:schemaLocation="http://www.springframework.org/schema/beans 
                            http://www.springframework.org/schema/beans/spring-beans.xsd
                            http://www.springframework.org/schema/context 
                            http://www.springframework.org/schema/context/spring-context-3.1.xsd
                            http://www.springframework.org/schema/tx
                            http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
                            http://www.springframework.org/schema/jdbc
                            http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
                            http://www.springframework.org/schema/security
                            http://www.springframework.org/schema/security/spring-security-3.1.xsd
                            http://www.springframework.org/schema/util 
                            http://www.springframework.org/schema/util/spring-util-3.1.xsd">


        <security:http entry-point-ref="casEntryPoint"
        use-expressions="true">
        <security:intercept-url pattern="/" access="permitAll" />

        <security:intercept-url pattern="/index.jsp"
            access="permitAll" />
        <security:intercept-url pattern="/cas-logout.jsp"
            access="permitAll" />
        <security:intercept-url pattern="/casfailed.jsp"
            access="permitAll" />

        <security:intercept-url access="hasRole('ROLE_MEMBER_INQUIRY')"
            pattern="/visit**" />

        <security:custom-filter ref="requestSingleLogoutFilter"
            before="LOGOUT_FILTER" />
        <security:custom-filter ref="singleLogoutFilter"
            before="CAS_FILTER" />
        <security:custom-filter ref="casFilter"
            position="CAS_FILTER" />


        <security:logout logout-success-url="/cas-logout.jsp" />
    </security:http>

    <security:authentication-manager alias="authManager">
        <security:authentication-provider
            ref="casAuthProvider" />
    </security:authentication-manager>



    <security:ldap-server id="ldapServer"
        url="ldaps://dvldap01.uftwf.dev:636/dc=uftwf,dc=dev" manager-dn="cn=xxx,dc=uftwf,dc=dev"
        manager-password="xxx" />

    <security:ldap-user-service id="userServiceLDAP"
        server-ref="ldapServer" user-search-base="ou=webusers"
        user-search-filter="(uid={0})" group-search-base="ou=groups"
        group-role-attribute="cn" group-search-filter="(uniqueMember={0})"
        role-prefix="ROLE_" />

    <!-- This filter handles a Single Logout Request from the CAS Server -->
    <bean id="singleLogoutFilter" class="org.jasig.cas.client.session.SingleSignOutFilter" />
    <!-- This filter redirects to the CAS Server to signal Single Logout should 
        be performed -->
    <bean id="requestSingleLogoutFilter"
        class="org.springframework.security.web.authentication.logout.LogoutFilter"
        p:filterProcessesUrl="/j_spring_cas_security_logout">
        <constructor-arg
            value="https://${cas.server.host}/cas-server-webapp/logout" />
        <constructor-arg>
            <bean
                class="org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler" />
        </constructor-arg>
    </bean>

    <bean id="serviceProperties" class="org.springframework.security.cas.ServiceProperties"
        p:service="http://wcmisdlin07.uftmasterad.org:8080/SchoolVisitLocked/j_spring_cas_security_check"
        p:authenticateAllArtifacts="true" />

    <bean id="casEntryPoint"
        class="org.springframework.security.cas.web.CasAuthenticationEntryPoint"
        p:serviceProperties-ref="serviceProperties"
        p:loginUrl="https://6dvews01.uftwf.dev:8443/cas-server-webapp/login" />

    <bean id="casFilter"
        class="org.springframework.security.cas.web.CasAuthenticationFilter"
        p:authenticationManager-ref="authManager" p:serviceProperties-ref="serviceProperties"
        p:proxyGrantingTicketStorage-ref="pgtStorage"
        p:proxyReceptorUrl="/j_spring_cas_security_proxyreceptor">
        <property name="authenticationDetailsSource">
            <bean
                class="org.springframework.security.cas.web.authentication.ServiceAuthenticationDetailsSource" />
        </property>

        <property name="authenticationFailureHandler">
            <bean
                class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler"
                p:defaultFailureUrl="/casfailed.jsp" />
        </property>


        <property name="authenticationSuccessHandler">
            <bean
                class="org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler"
                p:defaultTargetUrl="/visit" />
        </property>
    </bean>
    <!-- NOTE: In a real application you should not use an in memory implementation. 
        You will also want to ensure to clean up expired tickets by calling ProxyGrantingTicketStorage.cleanup() -->
    <bean id="pgtStorage"
        class="org.jasig.cas.client.proxy.ProxyGrantingTicketStorageImpl" />
    <bean id="casAuthProvider"
        class="org.springframework.security.cas.authentication.CasAuthenticationProvider"
        p:serviceProperties-ref="serviceProperties" p:key="casAuthProviderKey">
        <property name="authenticationUserDetailsService">
            <bean
                class="org.springframework.security.core.userdetails.UserDetailsByNameServiceWrapper">
                <constructor-arg ref="userServiceLDAP" />
            </bean>
        </property>



        <property name="ticketValidator">
            <bean class="org.jasig.cas.client.validation.Cas20ServiceTicketValidator">
                <constructor-arg index="0"
                    value="https://6dvews01.uftwf.dev:8443/cas-server-webapp" />
            </bean>
        </property>
    </bean>

    <!-- Configuration for the environment can be overriden by system properties -->
    <context:property-placeholder
        system-properties-mode="OVERRIDE" properties-ref="environment" />

    <util:properties id="environment">
        <prop key="cas.service.host">wcmisdlin07.uftmasterad.org:8443</prop>
        <prop key="cas.server.host">6dvews01.uftwf.dev:8443</prop>
    </util:properties>
</beans>

最佳答案

您使用占位符来表示属性,例如“${cas.server.host}”,这些属性必须在属性文件中定义并由 spring 解析。在您的类路径中创建一个新的属性文件“your.properties”并将其添加到您的上下文中:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
    <value>your.properties</value>
</property>
</bean>

你的.properties:

cas.server.host=http://localhost/abc

关于java - Spring XML 错误 : Could not resolve placeholder 'cas.server.host' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12354680/

相关文章:

java - 如何从 linux 服务器 java web 应用程序访问本地路径?

java - 通过 RMI : any sense? 访问 session 范围的 bean

jquery - jquery 轮询不会发生 HttpSession 超时

azure - 应用程序在一段时间后显示 CORS 错误 (AZURE AD)

java - 解析来自 http get 的多部分响应

java - 如何在 Java 中使用 CacheBuilder 构建和使用缓存

java "generic generic type"

spring - HTTP 状态 400 - 所需的整数参数 'id' 不存在

java - Spring3 JPA (Hibernate4) 不持久

spring - org.springframework.web.filter.CharacterEncodingFilter 无法转换为 javax.servlet.Filter