【问题标题】:org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'webSecurityConfig' [duplicate]org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为“webSecurityConfig”的bean时出错[重复]
【发布时间】:2017-11-08 17:43:59
【问题描述】:

每当我运行我的 Spring MVC 应用程序时都会遇到此错误。我一直在尝试集成 Spring Security,但未能成功注入我的自定义 AuthenticationSuccessHandler,因此出现以下与应用程序上下文有关的错误:

2017-11-07 16:05:03 ERROR ContextLoader:350 - Context initialization failed
org.springframework.beans.factory.UnsatisfiedDependencyException: \
  Error creating bean with name 'webSecurityConfig': \
    Unsatisfied dependency expressed through field 'auth'; \
      nested exception is
        org.springframework.beans.factory.NoSuchBeanDefinitionException: \
          No qualifying bean of type \
            'org.springframework.security.web.authentication.AuthenticationSuccessHandler' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)

我在 GitHub 上有我的项目:https://github.com/riveraadrian571/Staging-Management-System-Modifed-.git。我正在使用 oracle 数据库,并且在 pom.xml 文件中使用的是我在本地存储库中拥有的 jdbc 驱动程序,因此您可能想要更改它。我也在使用 tomcat 服务器来运行应用程序。提前致谢。

【问题讨论】:

标签: java spring spring-mvc


【解决方案1】:

在 WebSecurityConfig 你有

@Autowired
AuthenticationSuccessHandler  auth;

这是一个接口。您需要从标准中指定任何特定的实现:

所有已知的实现类:

  • ForwardAuthenticationSuccessHandler,

  • SavedRequestAwareAuthenticationSuccessHandler,

  • SimpleUrlAuthenticationSuccessHandler

@见Spring Docs

或者实现你的自定义。

【讨论】:

  • 我在同一个包中创建了一个名为 AuthSuccessHandler 的类,我认为它可以通过 autowire 注入到 WebSecurityConfig 中。这是不对的,甚至是不可能的吗?
  • 除了有点混乱的名字之外,你的方式是对的。现在您可以将处理程序自动连接到 WebSecurityConfig
猜你喜欢
  • 2021-09-21
  • 2019-01-22
  • 2021-11-17
  • 2021-08-25
  • 2021-08-13
  • 2018-11-03
  • 2021-09-18
  • 2019-10-02
  • 1970-01-01
相关资源
最近更新 更多