Bean没找到spring-saml

时间:2017-10-24 13:46:54

标签: java spring maven spring-security spring-saml

我的spring-saml 1.0.2-RELEASE弹簧配置有问题。这是错误:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myBean' defined in file [C:\mypath\myBean.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [java.util.Map]: : Cannot find class [org.springframework.security.saml.metadata.MetadataGeneratorFilter] for bean with name 'metadataGeneratorFilter' defined in ServletContext resource [/WEB-INF/config/samlSecurityContext.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.security.saml.metadata.MetadataGeneratorFilter; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.security.saml.metadata.MetadataGeneratorFilter] for bean with name 'metadataGeneratorFilter' defined in ServletContext resource [/WEB-INF/config/samlSecurityContext.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.security.saml.metadata.MetadataGeneratorFilter
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:738) ~[spring-beans-3.2.6.RELEASE.jar:3.2.6.RELEASE]
...

据我所见,我找不到bean MetadataGeneratorFilter,它以这种方式定义:

application.context.xml:

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context="http://www.springframework.org/schema/context"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd">

<context:annotation-config/>
<context:component-scan base-package="smc.services.*;smc.repositories.*"/>

<import resource="samlSecurityContext.xml"/>
...

samlSecurityContext.xml:

<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:security="http://www.springframework.org/schema/security"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context="http://www.springframework.org/schema/context"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
          http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd">


<!-- Scan for auto-wiring classes in spring saml packages -->
<context:component-scan base-package="org.springframework.security.saml"/>


<!-- Filter automatically generates default SP metadata -->
<bean id="metadataGeneratorFilter" class="org.springframework.security.saml.metadata.MetadataGeneratorFilter">
    <constructor-arg>
        <bean class="org.springframework.security.saml.metadata.MetadataGenerator">
            <property name="extendedMetadata">
                <bean class="org.springframework.security.saml.metadata.ExtendedMetadata">
                    <property name="idpDiscoveryEnabled" value="true"/>
                </bean>
            </property>
        </bean>
    </constructor-arg>
</bean>
...

我从示例项目中获取了示例,但我不确定与我的Spring版本的兼容性。这是我的pom.xml:

    <spring.version>3.2.6.RELEASE</spring.version>
    <spring.security.version>3.2.0.RELEASE</spring.security.version>
    ...
    <dependency>
        <groupId>org.springframework.security.extensions</groupId>
        <artifactId>spring-security-saml2-core</artifactId>
        <version>1.0.2.RELEASE</version>
    </dependency>

我的IDE说“在该软件包中没有定义bean”是指org.springframework.security.saml ...所以我很确定这个问题与我身边的一些弹簧配置有关,但是,对不起,我无法弄清楚哪个是错的。任何线索?提前致谢

1 个答案:

答案 0 :(得分:1)

问题是因为我在pom中添加了依赖项,但是我没有在classpath中添加jar。我修复了它在我的lib文件夹中添加jar,并在pom中将范围设置为 system ,如下所示:

class APIController extends Controller
{
    public function getProducts(Request $request)
    {
        $product = $request->input('product');
        $fromDate = $request->input('fromDate');
        $toDate = $request->input('toDate');
        $asortment = $request->input('asortment');

        $query = DB::select('exec test.dbo.Products @startDate = ?, @endDate = ?, @asortment = ?, @produkt = ?', [$fromDate, $toDate, $asortment, $product]);

        return datatables($query)->make(true);
    }

}

感谢Abhishek Bhatia