2016-11-17 30 views
2

'org.springframework.security.access.SecurityConfig':コンストラクタパラメータで表される満足度の低い依存性0:型[java.lang.String ]org.springframework.security.access.SecurityConfig:コンストラクタで表現されている満足していない依存性

どのようにこのエラーを解決しますか?

春4.1.3

コード

@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(); 
} 
} 

エラー

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設定

@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

表示com.abc.web.configurationとしてこの1上のトラブルにあなたを得ることができ、あなたのIDEの「自動インポート」機能として、正しいパッケージから引いている作ります.WebConfiguration – shazin

+0

@shazin、更新されました。 – ArthurDn

答えて

3

プロジェクトでしかし@Import({SecurityConfig.class})をインポートしているWebSecurityConfigurerAdapterを拡張するクラスはSecurityConfigurationです。

@Import({SecurityConfig.class}) 

へ:

だから、ライン変更してみてください

@Import({SecurityConfiguration.class}) 
+0

男、ありがとう! – ArthurDn

0

私はこれと同じ例外を持っていたが、それは私がAbstractAnnotationConfigDispatcherServletInitializer#getRootConfigClasses むしろorg.springframework.security.access.SecurityConfigのインスタンスを含む配列を返したことが判明私自身のWebSecurityConfigurerAdapterの実装よりも、SecurityConfigと命名されました。 org.springframework.security.access.SecurityConfigコンストラクタは、単一の文字列引数をとります。これは、満たされていない依存関係のオートワイヤリングエラーが発生している場所です。

あなたはSecurityConfigという名前のクラスを使用している場合は、輸入が

関連する問題