2017-08-09 8 views
0

spring handlerInterceptorAdapterの自動配線が失敗しています。ここでインターセプタの文字列beanのspring autowiringがNPEで失敗する

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pathInterceptor': 
Injection of autowired dependencies failed; nested exception is org.spring.framework.beans.factory.BeanCreationException: 
Could not autowire field:  
private java.lang.String com.mine.spring.interceptors.PathInterceptor.vendor; nested exception is java.lang.NullPointerException 
INFO | jvm 1 | 2017/08/09 23:29:41 |  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334) 
INFO | jvm 1 | 2017/08/09 23:29:41 |  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1218) 
INFO | jvm 1 | 2017/08/09 23:29:41 |  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543) 
INFO | jvm 1 | 2017/08/09 23:29:41 |  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) 
INFO | jvm 1 | 2017/08/09 23:29:41 |  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) 
INFO | jvm 1 | 2017/08/09 23:29:41 |  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
INFO | jvm 1 | 2017/08/09 23:29:41 |  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) 

はspringxmlファイル

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

からsnipetです...

<bean id="vendor" class="java.lang.String" c:_0="MyVendor"/> 

<mvc:interceptors> 
<bean class="com.mine.spring.interceptors.PathInterceptor" /> 
</mvc:interceptors> 

ここでは、Javaクラスからの抜粋

@Component 
public class PathInterceptor extends HandlerInterceptorAdapter { 

@Autowired 
@Qualifier("vendor") 
private String vendor; 

思考は何ですか?

+0

このリンクをたどるhttps://stackoverflow.com/a/36315807/3003337 – surya

答えて

0

あなたのString bean(heh)構文が間違っていると思います。

<bean id="vendor" class="java.lang.String"> 
    <constructor-arg value="MyVendor"/> 
</bean> 
+0

私はこれを常に行い、正常に動作します。 xmlns:c = "http://www.springframework.org/schema/c" –

+0

https://dzone.com/articles/spring-31-constructorの名前空間にcを宣言するだけです。 –

0

標準オートワイヤリングをめちゃくちゃにされた私のコンテキストスキャンでカスタムオートワイヤリングライブラリのいくつかの種類がありました。カスタムライブラリを見つけ出し、それを削除してautowiringが正しく機能するようにするよりも、私はもうそれを追跡しませんでした。

関連する問題