SJS*_*SJS 3 java xml configuration spring xml-namespaces
有人可以告诉我在我的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>
Run Code Online (Sandbox Code Playgroud)
说明.基本上你在这里处理XML命名空间.Spring配置允许您使用来自不同命名空间的配置元素作为扩展基本beans
命名空间配置的方法,使用方便的特定于域的配置,如上面的安全配置.
如果您的配置文件集中在其中一个扩展名称空间上 - 再次,让我们使用安全性作为示例 - 如果您将默认名称空间声明为扩展名称空间而不是标准beans
名称空间,它可以清理该文件.那是什么
xmlns="http://www.springframework.org/schema/security"
Run Code Online (Sandbox Code Playgroud)
确实 - 它使安全性成为默认命名空间,这意味着您不必使用sec:
或作为前缀security:
.
但是当你创建security
默认值时,你必须在使用beans
命名空间元素时明确.因此beans:
前缀.
解.如果您希望beans
成为默认名称,只需将默认名称空间更改为beans
:
xmlns="http://www.springframework.org/schema/beans"
Run Code Online (Sandbox Code Playgroud)
替代方案.或者,如果你想输入更短的东西,你可以这样做
xmlns:b="http://www.springframework.org/schema/beans"
Run Code Online (Sandbox Code Playgroud)
代替
xmlns:beans="http://www.springframework.org/schema/beans"
Run Code Online (Sandbox Code Playgroud)
这将允许你做的事情
<b:bean id="beanId" class="x.y.z.BeanClass" />
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
6771 次 |
最近记录: |