匹配的通配符是严格的,但找不到元素'import'的声明



我正在为我的Maven Web应用程序使用Spring安全性,并且我已经创建了spring-security.xml文件来处理身份验证。在这种情况下,我正在尝试使用导入从另一个文件 Bean 导入一个 bean.xml Beans。当我这样做时,发生了以下错误。

匹配的通配符很严格,但找不到元素"import"的声明

豆类.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xml>
<beans xmlns = "http://www.springframework.org/schema/beans"
    xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation = "http://www.springframework.org/schema/beans     
    http://www.springframework.org/schema/beans/spring-beans.xsd">
    <bean id = "dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
     <property name = "driverClassName" value = "com.mysql.jdbc.Driver"/>
      <property name = "url" value = "jdbc:mysql://localhost:3306/Employee_Management"/>
      <property name = "username" value = "root"/>
      <property name = "password" value = "root"/>
   </bean>
   <bean id = "transactionManager" 
      class = "org.springframework.jdbc.datasource.DataSourceTransactionManager">
      <property name = "dataSource"  ref = "dataSource" />
   </bean>
   <bean id = "employeeJDBCTemplate" class = "com.utility.EmployeeJDBCTemplate">
     <property name = "dataSource"  ref = "dataSource" />
     <property name = "transactionManager" ref = "transactionManager"/>
   </bean>
   <bean class = "org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name = "prefix" value = "/WEB-INF/jsp/" />
      <property name = "suffix" value = ".jsp" />
   </bean>
</beans>

弹簧安全.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/security"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/security
    http://www.springframework.org/schema/security/spring-security.xsd">
    <import resource="Beans.xml"/>
    <http entry-point-ref="loginUrlAuthenticationEntryPoint" auto-config="true" authentication-manager-ref="authenticationManager">
        <intercept-url pattern="/j_spring_security_check" access="isAnonymous()"/>
        <intercept-url pattern="/login" access="isAnonymous()"/>
        <intercept-url pattern="/welcome" access="hasRole('ROLE_ADMIN')"/>
        <form-login login-processing-url="/j_spring_security_check" login-page="/login" default-target-url="/welcome"
            authentication-failure-url="/login?error" username-parameter="username"
            password-parameter="password" />
        <logout logout-url="/j_spring_security_logout" invalidate-session="true" logout-success-url="/login?logout"/>
    </http>
    <beans:bean id="employeeAuthenticationProvider" class="com.authentication.EmployeeAuthenticationProvider">
      <beans:property name="employeeJDBCTemplate" ref="employeeJDBCTemplate" />
    </beans:bean>
    <authentication-manager alias="authenticationManager">
        <authentication-provider ref="employeeAuthenticationProvider"/>
    </authentication-manager>
    <beans:bean id="loginUrlAuthenticationEntryPoint" class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint">
        <beans:constructor-arg value="/login"/>
    </beans:bean>
</beans:beans>

在这里,我使用了导入的bean文件中的"employeeJDBCTemplate"bean。但是导入标记会产生错误。spring-security.xml 和 Beans.xml 位于同一文件夹中。我也尝试将 Beans.xml 文件移动到资源文件夹。即便如此,我也遇到了同样的错误。使用的 Spring 版本是 4.3.4,Spring 安全版本是 4.2.0。请帮忙。

spring-security.xml中,默认命名空间是http://www.springframework.org/schema/security("安全"命名空间(而不是http://www.springframework.org/schema/beans("bean"命名空间(。 import元素是在"beans"命名空间中定义的,因此要访问它,您必须使用前缀限定<import> beans:

尝试

<beans:import resource="Beans.xml"/>

而不是

<import resource="Beans.xml"/>

最新更新