java – Spring 3 applicationContext-security-JDBC.xml有bean
发布时间:2020-12-15 08:39:30 所属栏目:Java 来源:网络整理
导读:有人可以告诉我在我的ApplicationContext中我必须使用bean:bean而不是bean以及如何修复它. ?xml version="1.0" encoding="UTF-8"?beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:beans="http://www.springframework.org/schema
有人可以告诉我在我的ApplicationContext中我必须使用bean:bean而不是bean以及如何修复它.
<?xml version="1.0" encoding="UTF-8"?> <beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jdbc="http://www.springframework.org/schema/jdbc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-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.0.xsd"> <http auto-config="true" use-expressions="true"> <intercept-url pattern="/friends/**" access="hasRole('ROLE_USER')" /> <form-login login-page="/login.html" default-target-url="/index.html" always-use-default-target="true" authentication-failure-url="/login.html?authfailed=true" /> </http> <authentication-manager alias="authenticationManager"> <authentication-provider> <jdbc-user-service data-source-ref="dataSource" /> </authentication-provider> </authentication-manager> <beans:bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <beans:property name="location" value="classpath:jdbc.properties" /> </beans:bean> <beans:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <beans:property name="driverClassName" value="${database.driver}" /> <beans:property name="url" value="${database.url}" /> <beans:property name="username" value="${database.user}" /> <beans:property name="password" value="${database.password}" /> <beans:property name="initialSize" value="5" /> <beans:property name="maxActive" value="10" /> </beans:bean> </beans:beans> 解决方法
说明.基本上你在这里处理XML命名空间. Spring配置允许您使用来自不同命名空间的配置元素作为扩展基本bean命名空间配置的方法,使用方便的特定于域的配置,如上面的安全配置.
如果您的配置文件集中在其中一个扩展名称空间上 – 再次,让我们使用安全性作为示例 – 如果您将默认名称空间声明为扩展名称空间而不是标准bean名称空间,它可以清理该文件.那是什么 xmlns="http://www.springframework.org/schema/security" 确实 – 它使安全性成为默认命名空间,这意味着您不必使用sec:或security:作为前缀. 但是当您将安全性设置为默认值时,则在使用beans命名空间元素时必须明确.因此bean:前缀. 解.如果您更喜欢bean作为默认值,只需将默认命名空间更改为beans: xmlns="http://www.springframework.org/schema/beans" 替代方案.或者,如果你想输入更短的东西,你可以这样做 xmlns:b="http://www.springframework.org/schema/beans" 代替 xmlns:beans="http://www.springframework.org/schema/beans" 这将允许你做的事情 <b:bean id="beanId" class="x.y.z.BeanClass" /> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |