2016-03-21 828 views
0

現在、Webアプリケーションをテストしようとしていますが、BeanInstantiationExceptionおよびBeanCreationExceptionの原因となるWebsphere 8.5を起動しようとすると、NullPointerExceptionが発生し続けます。 mvc-dispatcher-servlet.xmlファイルでアノテーションを使い、Beanを削除しようとしましたが、同じエラーが発生したままですが、別のBeanを使用しています。私はこれを実行するために私が何を変える必要があるのか​​分からない。BeanInstantiationExceptionが原因でBeanInstantiationExceptionが発生しました:名前

MVC-ディスパッチャ-servlet.xml

<beans xmlns="http://www.springframework.org/schema/beans" 
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xmlns:jee="http://www.springframework.org/schema/jee" 
xmlns:aop="http://www.springframework.org/schema/aop" 
xsi:schemaLocation=" 
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd 
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc.xsd 
    http://www.springframework.org/schema/jee 
    http://www.springframework.org/schema/jee/spring-jee-4.0.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context.xsd 
    http://www.springframework.org/schema/aop/ 
    http://www.springframework.org/schema/aop/spring-aop-4.1.xsd"> 

<context:component-scan base-package="com.trac.controller" /> 
<context:component-scan base-package="com.trac.model" /> 

<mvc:annotation-driven /> 

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
    <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> 
    <property name="prefix" value="/WEB-INF/pages/" /> 
    <property name="suffix" value=".jsp" /> 
</bean> 

<mvc:resources mapping="/resources/**" location="/resources/" /> 

<!-- Configure to plugin JSON as request and response in method handler --> 
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"> 
    <property name="messageConverters"> 
     <list> 
      <ref bean="jsonMessageConverter"/> 
     </list> 
    </property> 
</bean> 

<!-- Configure bean to convert JSON to POJO and vice versa --> 
<bean id="jsonMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"> 
</bean> 

<bean id="agencyDao" class="com.trac.dao.AgencyDao"> 
    <property name="dataSource" ref="dataSource"/> 
</bean> 
<bean id="subsidyDao" class="com.trac.dao.SubsidyDao"> 
    <property name="dataSource" ref="dataSource"/> 
</bean> 
<bean id="agentDao" class="com.trac.dao.AgentDao"> 
    <property name="dataSource" ref="dataSource"/> 
</bean> 
<bean id="verificationDao" class="com.trac.dao.VerificationDao"> 
    <property name="dataSource" ref="dataSource"/> 
</bean> 

<bean id="mainController" class="com.trac.controller.MainController"> 
    <property name="sessionBean" ref="sessionBean"></property> 
    <property name="racfGroup" ref="racfGroup"></property> 
</bean> 

<bean id="racfGroup" class="com.trac.verification.RacfGroupData"> 
    <property name="securityService" ref="securityService"/> 
</bean> 

<bean id="securityService" class="com.security.client.services.SecurityService"/> 

<jee:jndi-lookup id="dataSource" jndi-name="jdbc/aoa" resource-ref="true"/> 

(豆が開始される)MainController.java

@Controller 
public class MainController { 

private CompanyOrgVerification org = new CompanyOrgVerification(); 

@Autowired 
private SessionBean session; 
private RacfGroupData racfGroup; 

//returns the agent search page 
@RequestMapping(URIConstants.WELCOME_PAGE) 
public ModelAndView welcome(HttpServletRequest request){ 

    session.setUserId("T5575"); 
    session.setPermission("INFOA", "U"); 

    if(racfGroup.getRacfGroups(session.getUserId())){ 
     session.setPermission("INFOA", "U"); 
     return new ModelAndView("index"); 
    }else{ 
     ModelAndView error = new ModelAndView(); 
     error.setViewName("error"); 
     return error; 
    } 
}public SessionBean getSessionBean(){ 
    return session; 
} 
public void setSessionBean(SessionBean session){ 
    this.session = session; 
} 
public RacfGroupData getRacfGroup(){ 
    return racfGroup; 
} 
public void setRacfGroup(RacfGroupData racfGroup){ 
    this.racfGroup = racfGroup; 
} 

}

RacfGroupData.java

public class RacfGroupData { 
    private SecurityService securityService; 

    static{ 
     SystemProperties.setProperty("RacfAttempts", String.valueOf(ATTEMPTS)); 
     SystemProperties.setProperty("RacfServerIP", SERVER_IP); 
     SystemProperties.setProperty("RacfServerKey", SERVER_KEY); 
     SystemProperties.setProperty("RacfTimeout", String.valueOf(TIMEOUT)); 
    } 
    // get racf groups for a given user ID. 
    public boolean getRacfGroups(String userID){ 
     GroupLookupResponse groups = securityService.getGroups(userID); 
     Iterator<Group> groupList = groups.getGroups().iterator(); 
     return validateGroup(groupList); 
    } 
    public SecurityService getSecurityService(){ 
     return securityService; 
    } 
    public void setSecurityService(SecurityService securityService){ 
     this.securityService = securityService; 
    } 

エラー

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'racfGroup': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.security.client.services.SecurityService com.trac.verification.RacfGroupData.securityService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityService' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.security.client.services.SecurityService]: Constructor threw exception; nested exception is java.lang.NullPointerException: name 
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) 
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) 
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:320) 
... 98 more 
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.security.client.services.SecurityService com.trac.verification.RacfGroupData.securityService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityService' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.security.client.services.SecurityService]: Constructor threw exception; nested exception is java.lang.NullPointerException: name 
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:508) 
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) 
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289) 
... 106 more 
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityService' defined in ServletContext resource [/WEB-INF/mvc-dispatcher-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.security.client.services.SecurityService]: Constructor threw exception; nested exception is java.lang.NullPointerException: name 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1076) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1021) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) 
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1014) 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:957) 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:855) 
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480) 
... 108 more 
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.security.client.services.SecurityService]: Constructor threw exception; nested exception is java.lang.NullPointerException: name 
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:164) 
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1069) 
... 119 more 
Caused by: java.lang.NullPointerException: name 
at feign.Util.checkNotNull(Util.java:99) 
at feign.Target$HardCodedTarget.<init>(Target.java:67) 
at feign.Target$HardCodedTarget.<init>(Target.java:62) 
at feign.Feign$Builder.target(Feign.java:175) 
at com.security.client.services.SecurityService.<init>(SecurityService.java:29) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:80) 
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:57) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:539) 
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148) 
... 121 more 

SecurityService

public class SecurityService implements ISecurityService 
{ 
private JacksonDecoder _decoder = new JacksonDecoder(); 
private SecurityServiceApi _securityServiceApi = Feign.builder() 
    .decoder(_decoder) 
    .encoder(new JacksonEncoder()) 
    .target(SecurityServiceApi.class, System.getProperty("securityServicesBaseUrl")); 

/** 
* @param id 
* @param useTestGroups 
* @return see overriden class or implemented interface 
* @see com.security.client.services.ISecurityService#getUser(java.lang.String, boolean) 
*/ 
@Override 
public UserLookupResponse getUser(String id, boolean useTestGroups) 
{ 
    return _securityServiceApi.getUser(id, useTestGroups); 
} 

/** 
* @param id 
* @param useTestGroups 
* @return see overriden class or implemented interface 
* @see com.security.client.services.ISecurityService#getGroups(java.lang.String, boolean) 
*/ 
@Override 
public GroupLookupResponse getGroups(String id, boolean useTestGroups) 
{ 
    return _securityServiceApi.getGroups(id, useTestGroups); 
} 

/** 
* @param id 
* @return see overriden class or implemented interface 
* @see com.security.client.services.ISecurityService#getUser(java.lang.String) 
*/ 
@Override 
public UserLookupResponse getUser(String id) 
{ 
    return getUser(id, false); 
} 

/** 
* @param id 
* @param testGroups 
* @return see overriden class or implemented interface 
* @see com.security.client.services.ISecurityService#getUser(java.lang.String, byte[]) 
*/ 
@Override 
public UserLookupResponse getUser(String id, byte[] testGroups) 
{ 
    UserLookupRequest userLookupRequest = new UserLookupRequest(); 
    userLookupRequest.setTestGroupsBase64(Base64.encodeBase64String(testGroups)); 

    return _securityServiceApi.getUser(id, userLookupRequest); 
} 

/** 
* @param id 
* @return see overriden class or implemented interface 
* @see com.security.client.services.ISecurityService#getGroups(java.lang.String) 
*/ 
@Override 
public GroupLookupResponse getGroups(String id) 
{ 
    return getGroups(id, false); 
} 

/** 
* @param id 
* @param groups 
* @return see overriden class or implemented interface 
* @see com.security.client.services.ISecurityService#updateGroups(java.lang.String, java.util.List) 
*/ 
@Override 
public void updateGroups(String id, List<Group> groups) 
{ 
    _securityServiceApi.updateGroups(id, createGroupUpdateRequest(groups)); 
} 

/** 
* @param id 
* @param groups see overriden class or implemented interface 
* @see com.security.client.services.ISecurityService#addGroups(java.lang.String, java.util.List) 
*/ 
@Override 
public void addGroups(String id, List<Group> groups) 
{ 
    _securityServiceApi.addGroups(id, createGroupUpdateRequest(groups)); 
} 

/** 
* @param id 
* @param groupName see overriden class or implemented interface 
* @see com.security.client.services.ISecurityService#removeGroup(java.lang.String, java.lang.String) 
*/ 
@Override 
public void removeGroup(String id, String groupName) 
{ 
    _securityServiceApi.removeGroup(id, groupName); 

} 

private GroupUpdateRequest createGroupUpdateRequest(List<Group> groups) 
{ 
    GroupUpdateRequest groupUpdateRequest = new GroupUpdateRequest(); 
    groupUpdateRequest.getGroups().addAll(groups); 

    return groupUpdateRequest; 
} 

SecurityClient Beanはセキュリティクライアント0.jarと呼ばれる瓶から来ています。どんな提案もありがとう

+0

使用この

@Autowired private SessionBean session; @Autowired private RacfGroupData racfGroup; 

SecurityService.classでリファクタリングこのライン

private JacksonDecoder _decoder = new JacksonDecoder(); private SecurityServiceApi _securityServiceApi = Feign.builder() .decoder(_decoder) .encoder(new JacksonEncoder()) .target(SecurityServiceApi.class, System.getProperty("securityServicesBaseUrl")); 

? – 11thdimension

+0

EDIT:エラーログを追加するのを忘れました。 – Karson074

+0

例外は 'SecurityService'クラスから来ています。そのためのコードを追加する必要があります。 SecurityServiceのコンストラクタにNPEを設定せずに投げるオブジェクトがあります。また@kakashiのハタケが指摘したように、コントローラメソッドが呼び出されたときにNPEを投げるので、 'MainController'に' ReacfGroupData'をautowireする必要があります。しかし、現在の例外は、SecurityServiceが適切に初期化されていないためです。 – 11thdimension

答えて

0

MainController.javaprivate RacfGroupData racfGroup;あなたはAutowired両方の豆のために必要があります。あなたはNPEを取得しているこの

@Autowired 
private JacksonDecoder _decoder; 

private SecurityServiceApi _securityServiceApi; 

@PostConstruct 
public void init() { 
_securityServiceApi = Feign.builder() 
     .decoder(_decoder) 
     .encoder(new JacksonEncoder()) 
     .target(SecurityServiceApi.class, System.getProperty("securityServicesBaseUrl")); 
} 
+0

あなたの提案通りにしましたが、私はまだ同じエラーが発生しています。 – Karson074

+0

また、SecurityService.classにデフォルトのコンストラクタを追加します.RacfGroupData.classを追加します。また、SecurityService.classに@Autowired依存関係を設定します。 –

+0

あなたは何を意味するのかよくわかりません。私はクラスをインスタンス化するためにSpring Beanを使用するのが初めてです。 SecurityServiceは、自分のプロジェクトにインポートしていて、Beanを使ってアクセスしようとしているjarです。コンストラクタはどこに追加すればよいですか? – Karson074

関連する問題