私は、次があります。エラー名でBeanを作成する 'ecosmart_BackupService':私はビーンインスタンスは、注文
ERRORしようとしています
Caused by: org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'myApp_DropboxService' defined in URL
[jar:file:/E:/Cuba/myApp/deploy/tomcat/webapps/app-core/WEB-INF/lib/app-core-0.1-SNAPSHOT.jar!/com/daryn/myApp/service/DropboxServiceBean.class]:
Instantiation of bean failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [com.daryn.myapp.service.DropboxServiceBean]: Constructor
threw exception; nested exception is java.lang.NullPointerException
現在のコード:私は、次のエラーを取得しておく不満依存関係がフィールドを通して表現 'をdropboxService';ネストされた例外はorg.springframework.beans.factory.BeanCreationExceptionです: 'ecosmart_DropboxService'という名前のBeanを作成中にエラーが発生しました:initメソッドの呼び出しに失敗しました。ネストされた例外は、春には、オブジェクトが構築された後にのみフィールドを注入し、ACCESS_TOKEN
でもその前に初期化されて、あなたのケースでjava.lang.NullPointerExceptionが
@Service(DropboxService.NAME)
public class DropboxServiceBean implements DropboxService {
@Inject
private CustomConfig customConfig;
private String ACCESS_TOKEN = "";
DbxRequestConfig config;
DbxClientV2 client;
@PostConstruct
public void postConstruct() {
System.out.println("**************Running post construct");
ACCESS_TOKEN = customConfig.getDropboxAppToken();
config = new DbxRequestConfig("dropbox/java-tutorial", "en_US");
client = new DbxClientV2(config, ACCESS_TOKEN);
}
これを '@ PostConstruct'アノテーション付きメソッドに入れます。注入は、オブジェクトが作成された後にのみ行うことができます。 –
@postconstructを試して更新しました。しかし、それはまだ動作していません。おそらく、Beanが起動時にCustomConfig Beanを起動する前にBeanがインスタンス化されているためです... – Daryn
あなたは 'myApp_DropboxService'で始めましたが、今は' ecosmart_BackupService'に問題がありますので、問題はこのクラスのコードとおそらく同じです。 – Oleg