2016-11-17 3 views
2

'org.springframework.security.access.SecurityConfig': Unbefriedigte Abhängigkeit ausgedrückt durch Konstruktorparameter 0: Keine qualifizierende Bean vom Typ [java.lang.String ]org.springframework.security.access.SecurityConfig: Unbefriedigte Abhängigkeit ausgedrückt durch Konstruktor

Wie beheben Sie diesen Fehler?

Frühling 4.1.3

-Code

@Configuration 
@EnableWebSecurity 
public class SecurityConfiguration extends WebSecurityConfigurerAdapter { 
@Autowired 
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { 
    auth.inMemoryAuthentication().withUser("user").password("abc").roles("DBA", "ADMIN"); 
} 

@Override 
protected void configure(HttpSecurity http) throws Exception { 
    http.authorizeRequests() 
      .antMatchers("/abc/**").hasRole("ADMIN") 
      .anyRequest().authenticated(); 
} 
} 

Fehler

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.security.access.SecurityConfig': Unsatisfied dependency expressed through constructor parameter 0: No qualifying bean of type [java.lang.String] found for dependency [java.lang.String]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [java.lang.String] found for dependency [java.lang.String]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {} 
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749) 
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:189) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1143) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1046) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) 
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:776) 
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861) 
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) 
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:169) 
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5168) 
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:154) 
... 10 more 
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [java.lang.String] found for dependency [java.lang.String]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {} 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1406) 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1057) 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1019) 
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:835) 
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741) 
... 26 more 

web.xml

<context-param> 
    <param-name>contextClass</param-name> 
    <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value> 
</context-param> 
<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>com.abc.web.configuration.WebConfiguration</param-value> 
</context-param> 

<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 

<servlet> 
    <servlet-name>MVC</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextClass</param-name> 
     <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value> 
    </init-param> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>com.abc.web.configuration.WebConfiguration</param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
    <servlet-name>MVC</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 

<filter> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
</filter> 

<filter-mapping> 
    <filter-name>springSecurityFilterChain</filter-name> 
    <url-pattern>/*</url-pattern> 
    <dispatcher>ERROR</dispatcher> 
    <dispatcher>REQUEST</dispatcher> 
</filter-mapping> 

Web Config

@EnableWebMvc 
@Configuration 
@Import({SecurityConfig.class}) 
@ImportResource("classpath*:contexts/all-beans.xml") 
@ComponentScan(basePackages = "com.abc.web") 
public class WebConfiguration extends WebMvcConfigurerAdapter { 
@Override 
public void addCorsMappings(CorsRegistry registry) { 
    registry.addMapping("/") 
      .allowedOrigins("*"); 
} 
} 
+0

anzeigen com.abc.web.configuration bekommen .WebConfiguration – shazin

+0

@shazin, aktualisiert. – ArthurDn

Antwort

3

Du @Import({SecurityConfig.class}) jedoch in Ihrem Projekt die Klasse zu importieren, die WebSecurityConfigurerAdapter erstreckt, ist SecurityConfiguration.

So versuchen, die Linie zu ändern:

@Import({SecurityConfig.class}) 

zu:

@Import({SecurityConfiguration.class}) 
+0

Mann, danke !!! – ArthurDn

0

ich diese gleiche Ausnahme hatte, und es stellt sich heraus, dass mein AbstractAnnotationConfigDispatcherServletInitializer#getRootConfigClasses ein Array zurückkehrt eine Instanz von org.springframework.security.access.SecurityConfig eher enthaltenden als meine eigene Implementierung von WebSecurityConfigurerAdapter, die zufällig auch SecurityConfig genannt wurde. Der org.springframework.security.access.SecurityConfig -Konstruktor verwendet ein einzelnes Zeichenfolgenargument, von dem der Fehler "Unbefriedigter Abhängigkeitsauthentifizierungsfehler" stammt.

Wenn Sie eine Klasse mit dem Namen SecurityConfig verwenden, stellen Sie die Einfuhren aus den richtigen Pakete ziehen, als IDE „Auto-Import“ Funktion, die Sie in Schwierigkeiten auf diesem als

Verwandte Themen