2017-03-01 16 views
0

봄 오류 :컨텍스트 초기화에 실패했습니다. 내가 런타임에 Hybris 플랫폼을 실행하려고하면이 오류를 얻을 경우, NoSuchMethodException

WARN [localhost-startStop-1] [TenantIgnoreXmlWebApplicationContext] Exception encountered during context initialization - cancelling refresh at 
tempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'checkoutController': Injection of resource depend 
encies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'autoLoginStrategy' de 
fined in ServletContext resource [/WEB-INF/config/common-spring-security-config.xml]: Cannot resolve reference to bean 'rememberMeServices' whil 
e setting bean property 'rememberMeServices'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean w 
ith name 'defaultRememberMeServices' defined in ServletContext resource [/WEB-INF/config/common-spring-security-config.xml]: Instantiation of be 
an failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.sap.hybris.fs.storefront.securit 
y.AcceleratorRememberMeServices]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.sap.hybris.fs.storefron 
t.security.AcceleratorRememberMeServices.<init>() 

AcceleratorRememberMeServices 클래스는 이것이다 :

/* 
* [y] hybris Platform 
* 
* Copyright (c) 2000-2015 hybris AG 
* All rights reserved. 
* 
* This software is the confidential and proprietary information of hybris 
* ("Confidential Information"). You shall not disclose such Confidential 
* Information and shall use it only in accordance with the terms of the 
* license agreement you entered into with hybris. 
* 
* 
*/ 
package com.sap.hybris.fs.storefront.security; 

import de.hybris.platform.acceleratorservices.urlencoder.UrlEncoderService; 
import de.hybris.platform.acceleratorstorefrontcommons.constants.WebConstants; 
import de.hybris.platform.commercefacades.customer.CustomerFacade; 
import de.hybris.platform.commercefacades.storesession.StoreSessionFacade; 
import de.hybris.platform.commerceservices.security.SecureTokenService; 
import de.hybris.platform.commerceservices.strategies.CheckoutCustomerStrategy; 
import de.hybris.platform.servicelayer.i18n.CommonI18NService; 
import de.hybris.platform.servicelayer.user.UserService; 
import com.sap.hybris.fs.storefront.web.wrappers.RemoveEncodingHttpServletRequestWrapper; 

import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 

import org.apache.commons.lang.StringUtils; 
import org.springframework.beans.factory.annotation.Required; 
import org.springframework.security.authentication.RememberMeAuthenticationToken; 
import org.springframework.security.core.Authentication; 
import org.springframework.security.core.userdetails.UserDetails; 
import org.springframework.security.core.userdetails.UserDetailsService; 
import org.springframework.security.web.authentication.rememberme.TokenBasedRememberMeServices; 


public class AcceleratorRememberMeServices extends TokenBasedRememberMeServices 
{ 
    public AcceleratorRememberMeServices(String key, UserDetailsService userDetailsService) { 
     super(key, userDetailsService); 
     // YTODO Auto-generated constructor stub 
    } 

    private UserService userService; 
    private CustomerFacade customerFacade; 
    private CheckoutCustomerStrategy checkoutCustomerStrategy; 
    private StoreSessionFacade storeSessionFacade; 
    private CommonI18NService commonI18NService; 
    private UrlEncoderService urlEncoderService; 
    private SecureTokenService secureTokenService; 

    @Override 
    protected void setCookie(final String[] tokens, final int maxAge, final HttpServletRequest request, 
          final HttpServletResponse response) 
    { 
     if (!getCheckoutCustomerStrategy().isAnonymousCheckout()) 
     { 
      super.setCookie(tokens, maxAge, new RemoveEncodingHttpServletRequestWrapper(request, getUrlEncodingPattern(request)), 
        response); 
     } 
    } 

    @Override 
    public void logout(final HttpServletRequest request, final HttpServletResponse response, final Authentication authentication) 
    { 
     super.logout(new RemoveEncodingHttpServletRequestWrapper(request, getUrlEncodingPattern(request)), response, authentication); 
    } 

    @Override 
    protected Authentication createSuccessfulAuthentication(final HttpServletRequest request, final UserDetails user) 
    { 
     getUserService().setCurrentUser(getUserService().getUserForUID(user.getUsername())); 

     if (StringUtils.isNotEmpty(getUrlEncoderService().getUrlEncodingPattern())) 
     { 
      getCustomerFacade().rememberMeLoginSuccessWithUrlEncoding(getUrlEncoderService().isLanguageEncodingEnabled(), 
        getUrlEncoderService().isCurrencyEncodingEnabled()); 
     } 
     else 
     { 
      getCustomerFacade().loginSuccess(); 
     } 
     final RememberMeAuthenticationToken auth = new RememberMeAuthenticationToken(getKey(), user, user.getAuthorities()); 
     auth.setDetails(getAuthenticationDetailsSource().buildDetails(request)); 
     return auth; 
    } 

    @Override 
    protected String retrievePassword(final Authentication authentication) 
    { 
     return getUserService().getUserForUID(authentication.getPrincipal().toString()).getEncodedPassword(); 
    } 

    protected String getUrlEncodingPattern(final HttpServletRequest request) 
    { 
     final String encodingAttributes = (String) request.getAttribute(WebConstants.URL_ENCODING_ATTRIBUTES); 
     return StringUtils.defaultString(encodingAttributes); 
    } 

    protected UserService getUserService() 
    { 
     return userService; 
    } 

    @Required 
    public void setUserService(final UserService userService) 
    { 
     this.userService = userService; 
    } 

    protected CustomerFacade getCustomerFacade() 
    { 
     return customerFacade; 
    } 

    @Required 
    public void setCustomerFacade(final CustomerFacade customerFacade) 
    { 
     this.customerFacade = customerFacade; 
    } 

    protected CheckoutCustomerStrategy getCheckoutCustomerStrategy() 
    { 
     return checkoutCustomerStrategy; 
    } 

    @Required 
    public void setCheckoutCustomerStrategy(final CheckoutCustomerStrategy checkoutCustomerStrategy) 
    { 
     this.checkoutCustomerStrategy = checkoutCustomerStrategy; 
    } 

    protected UrlEncoderService getUrlEncoderService() 
    { 
     return urlEncoderService; 
    } 

    @Required 
    public void setUrlEncoderService(final UrlEncoderService urlEncoderService) 
    { 
     this.urlEncoderService = urlEncoderService; 
    } 


    protected StoreSessionFacade getStoreSessionFacade() 
    { 
     return storeSessionFacade; 
    } 

    @Required 
    public void setStoreSessionFacade(final StoreSessionFacade storeSessionFacade) 
    { 
     this.storeSessionFacade = storeSessionFacade; 
    } 

    protected CommonI18NService getCommonI18NService() 
    { 
     return commonI18NService; 
    } 

    @Required 
    public void setCommonI18NService(final CommonI18NService commonI18NService) 
    { 
     this.commonI18NService = commonI18NService; 
    } 

    protected SecureTokenService getSecureTokenService() 
    { 
     return secureTokenService; 
    } 

    @Required 
    public void setSecureTokenService(final SecureTokenService secureTokenService) 
    { 
     this.secureTokenService = secureTokenService; 
    } 
} 

빈 (bean)이 방법으로 선언 :

<alias name="defaultRememberMeServices" alias="rememberMeServices"/> 
    <bean id="defaultRememberMeServices" class="com.sap.hybris.fs.storefront.security.AcceleratorRememberMeServices" > 
     <property name="userDetailsService" ref="originalUidUserDetailsService" /> 
     <property name="key" value="fsstorefront" /> 
     <property name="cookieName" value="fsstorefrontRememberMe" /> 
     <property name="alwaysRemember" value="true" /> 
     <property name="userService" ref="userService"/> 
     <property name="useSecureCookie" value="false"/> 
     <property name="customerFacade" ref="customerFacade"/> 
     <property name="checkoutCustomerStrategy" ref="checkoutCustomerStrategy"/> 
     <property name="urlEncoderService" ref="urlEncoderService"/> 
     <property name="storeSessionFacade" ref="storeSessionFacade"/> 
     <property name="commonI18NService" ref="commonI18NService"/> 
     <property name="secureTokenService" ref="secureTokenService"/> 
    </bean> 

생성자 메소드에 문제가 있습니까? 아니면 Spring 설정의 문제인가? 누구에게나 귀중한 도움을 주셔서 감사합니다.

+0

어떻게 당신이 빈을 선언하는에 생성자 인자 주입 및 봄 의존성 주입에 대한 자세한 내용보기 : 귀하의 선언은 다음과 같이 될 것이다? – rmlan

+0

@rmlan 빈 선언을 추가했습니다. – sharkbait

답변

1

기본 생성자를 찾고 있으므로 <init>()입니다. 기본 생성자를 만들거나 빈을 선언 할 때 생성자 인수를 사용해야합니다.

이 경우 기존 TokenBasedRememberMeServices 클래스를 확장 중이므로 특성으로 삽입하는 대신 관련 생성자 인수 (key, userDefaultsService)로 bean을 선언해야합니다.

<bean id="defaultRememberMeServices" class="com.sap.hybris.fs.storefront.security.AcceleratorRememberMeServices" > 
    <!-- constructor arguments --> 
    <constructor-arg index="0" value="fsstorefront"/> 
    <constructor-arg index="1" ref="originalUidUserDetailsService" /> 

    <!-- rest of the properties --> 
    <property name="cookieName" value="fsstorefrontRememberMe" /> 
    <property name="alwaysRemember" value="true" /> 
    <property name="userService" ref="userService"/> 
    <property name="useSecureCookie" value="false"/> 
    <property name="customerFacade" ref="customerFacade"/> 
    <property name="checkoutCustomerStrategy" ref="checkoutCustomerStrategy"/> 
    <property name="urlEncoderService" ref="urlEncoderService"/> 
    <property name="storeSessionFacade" ref="storeSessionFacade"/> 
    <property name="commonI18NService" ref="commonI18NService"/> 
    <property name="secureTokenService" ref="secureTokenService"/> 
</bean> 

일반 here

+0

하지만이 public AcceleratorRememberMeServices (String key, UserDetailsService userDetailsService) { super (key, userDetailsService); } ' 으로 충분하지 않습니다. – sharkbait

+0

이것은 기본 (인수 없음) 생성자가 아닙니다. Spring은 bean을 생성 할 때 "key"와 "userDetailsService"에 무엇을 주입해야하는지 어떻게 알 수 있습니까? – rmlan

+0

그래서 어떤 방법으로 생성자를 만들어야합니까? – sharkbait