2016-11-23 5 views
0

私はを受け取りました。メソッドがあり、HSMをpingすることができます。HealthIndicatorにサービスをインジェクトするときのエラー

私は HealthIndicatorを実装するクラスでこの HSMServiceを注入したい
package com.app.ddd.services; 

import com.app.ddd.messages.EchoRequest; 

public class HSMService implements HSMServiceI { 

    private SynchronousEstablishedConnection connection; 
    private String genericGroupName; 

    public HSMService(EstablishedConnection connection, String genericGroupName) { 
     this.connection = new SynchronousEstablishedConnection(connection); 
     this.genericGroupName = genericGroupName; 
    } 

    @Override 
    public void ping() { 
     connection.submit(new EchoRequest()); 
    } 
} 

HSMHealthIndicator.java:

@Component 
public class HSMHealthIndicator implements HealthIndicator { 

    @Autowired 
    private HSMService hsmService; 

    private String host; 
    private int port; 

    private int checkHSMStatus() { 

     //just to test 
     if (hsmService == null) 
      System.out.println("hsmService null"); 
     return 0; 
    } 

    @Override 
    public Health health() { 

     if (checkHSMStatus() != 0) { 
      return Health.down().withDetail("Error Code", checkRKMSStatus()).build(); 
     } 
     return Health.up().build(); 
    } 

    public String getHost() { 
     return host; 
    } 

    public void setHost(String host) { 
     this.host = host; 
    } 

    public int getPort() { 
     return port; 
    } 

    public void setPort(int port) { 
     this.port = port; 
    } 

    public HSMService getHSMService() { 
     return hsmService; 
    } 

    public void setHSMService(HSMService hsmService) { 
     this.hsmService= hsmService; 
    } 

} 

このクラスはorg.springframework.boot.actuate.endpoint.Endpoint

を実装 HSMEndpoint.javaクラスによって使用されています

HSMEndpoint.javaの抜粋:

@Override 
public String invoke() { 

    HSMHealthIndicator h = new HSMHealthIndicator(); 
    h.setHost(this.getHost()); 
    h.setPort(this.getPort()); 
    Status s = h.health().getStatus(); 
    return "Status of the HSM : " + s.getCode(); 
} 

は最後HSMEndpoint.javaクラスHSMEndpointConfiguration.javaによって構成されている:

@Configuration 
public class HSMEndpointConfiguration{ 

    @Bean 
    //The value of hsm.host and the value of hsm.port are in application.properties 
    public Endpoint getHSMEndpoint(@Value("${hsm.host}")String host, @Value("${hsm.port}")int port) { 
     return new HSMEndpoint(host, port); 
    } 
} 

ルートエラーがある:org.springframework.beans.factory.NoSuchBeanDefinitionException:によって引き起こさ

。依存関係のある適格なBeanは見つかりません[com.app.ddd.services.HSMService]:autowire候補と見なされる少なくとも1つのbeanが必要です。依存注釈:

+0

ここで、タイプHSMServiceのBeanはありますか。 – Jobin

+0

HSMServiceのコードをパッケージ名 – developer

+0

と共にパッケージcom.app.ddd.services – Denis

答えて

1

HsmServiceクラスに次の行を追加..

@Service("hsmService") 

のでになる..

{org.springframework.beans.factory.annotation.Autowired(=真必須)@}
@Service("hsmService") 
public class HSMService implements HSMServiceI { 
+0

まだエラーがあります: 「hsmService」という名前のBeanを作成中にエラーが発生しました... コンストラクタパラメータ0で表されている満足度の低い依存関係。ネストされた例外はorg.springframework.beans.factory.NoSuchBeanDefinitionExceptionです:依存関係のある適格なBeanが見つかりません。[com.app.ddd.services.EstablishedConnection]:autowire候補と見なされる少なくとも1つのbeanが必要です。依存関係の注釈:{} – Denis

+0

@Denisはまだエラーが発生していますか? – Jobin

関連する問題