gpt4 book ai didi

java - 未找到 Bean spring-saml

转载 作者:行者123 更新时间:2023-12-02 12:05:51 26 4
gpt4 key购买 nike

我的 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...所以我很确定问题与我这边的一些 spring 配置有关,但是,抱歉,我不知道哪个是错误的。有什么线索吗?提前致谢

最佳答案

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

<dependency>
<groupId>org.springframework.security.extensions</groupId>
<artifactId>spring-security-saml2-core</artifactId>
<version>1.0.2.RELEASE</version>
<scope>system</scope>
<systemPath>${smc.lib.path}/spring-security-saml2-core-1.0.2.RELEASE.jar</systemPath>
</dependency>

感谢Abhishek Bhatia !

关于java - 未找到 Bean spring-saml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46912231/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com