【发布时间】:2013-02-02 23:21:45
【问题描述】:
我正在尝试在我的spring-security configuration xml 文件中使用我的application.properties 中的boolean 参数。
我不知道为什么我可以使用非布尔参数,但我得到一个布尔错误。
如何使用布尔参数?
这是我的 application.properties:
JDBC_CONNECTION_STRING=jdbc:mysql://localhost:3306/schema?user=username&password=password
protocol=http
USE_SECURE=false
我的 spring-security.xml 是:
< remember-me user-service-ref="internalUserDetails" data-source-ref="dataSource" key="this-is-my-key02203452416fw" use-secure-cookie="${USE_SECURE}" />
... 但我收到此错误: cvc-datatype-valid.1.2.1:“${USE_SECURE}”不是“布尔”的有效值
我也尝试设置USE_SECURE=False,但我再次遇到同样的错误。
如何在 spring 安全配置 xml 文件中使用布尔参数?
这是我的 web.xml:
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0" >
<display-name> Name-MyApp</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<!-- Servlets -->
<servlet>
<servlet-name>MyApp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Servlets Mappings -->
<servlet-mapping>
<servlet-name>MyApp</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/servlet-context.xml,
/WEB-INF/spring-security.xml
</param-value>
</context-param>
<!-- Filters -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>httpMethodFilter</filter-name>
<servlet-name>MyApp</servlet-name>
</filter-mapping>
<filter>
<filter-name>httpMethodFilter</filter-name>
<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
【问题讨论】:
-
你有
PropertyPlaceholderConfigurerconfifured 吗? -
我认为我不需要
PropertyPlaceholderConfigurer,同一个文件中的其他属性都可以正常工作,PropertyPlaceholderConfigurer如何帮助我获取布尔值? -
如何将
application.properties文件加载到spring? -
@ArunPJohny
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /> <property name="location" value="classpath:application.properties" /> </bean>属性文件中的其他值都加载好了,可能@zagyi是对的,稍后我会检查一下 -
它是一个 Web 应用程序吗?您在哪个文件中定义了
PropertyPlaceholderConfigbean?
标签: spring web-applications spring-mvc spring-security application-server