2011-04-09 61 views
3

有人可以告诉我什么在我的ApplicationContext我必须使用豆:豆,而不是豆,以及如何解决它。Spring 3 applicationContext-security-JDBC.xml有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> 

回答

7

说明。基本上你在这里处理XML命名空间。通过Spring配置,可以使用不同命名空间中的配置元素作为扩展名称空间配置的基本方法,方便使用特定于域的配置,例如上述情况下的安全配置。

如果您的配置文件集中在其中一个扩展名称空间上 - 再次以安全性为例 - 如果您将默认名称空间声明为扩展名称空间而不是标准,它可以清理文件beans命名空间。这就是

xmlns="http://www.springframework.org/schema/security" 

那样 - 它使安全默认的命名空间,这意味着你不必与sec:security:前缀它。

但是,当您将security设为默认值时,那么在使用beans命名空间元素时必须明确。因此前缀为beans:

解决方案。如果你喜欢beans是默认的,只要更改默认的命名空间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" />