これはコンフィグレーションクラスのBean定義です。コンフィグレーションクラスで初期化されても、Spring Beanはまだヌルです
@Bean(name = "applicationPropertiesDataService")
public com.ing.app.data.ApplicationPropertiesDataService
applicationPropertiesDataService() {
return new com.ing.app.data.ApplicationPropertiesDataService();
}
これは私が上記のBeanを使用しているクラスの私のbean定義です。
@Bean(name = "appRestTemplate")
public AppRestTemplate appRestTemplate() {
return new AppRestTemplate();
}
これはAppRestTemplateクラスです。 BeanがAppRestTemplate豆の前にインスタンス化されるにもかかわらず、私はヌルとしてautowired「applicationPropertiesDataService」Beanを取得しています、私は、なぜ把握することができません
import org.springframework.web.client.RestTemplate;
import com.ing.app.data.ApplicationPropertiesDataService;
import com.ing.app.interceptor.LoggingClientHttpRequestInterceptor;
public class AppRestTemplate extends RestTemplate {
@Autowired
private ApplicationPropertiesDataService applicationPropertiesDataService;
public AppRestTemplate() {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setOutputStreaming(false);
BufferingClientHttpRequestFactory bufferingClientHttpRequestFactory =
new BufferingClientHttpRequestFactory(requestFactory);
this.setRequestFactory(bufferingClientHttpRequestFactory);
if (isLoggingEnabled()) {
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>();
interceptors.add(new LoggingClientHttpRequestInterceptor());
this.setInterceptors(interceptors);
}
}
}
private boolean isLoggingEnabled() {
boolean isLoggingEnabled = false;
Optional<ApplicationProperties> applicationProperties = applicationPropertiesDataService.findByCategoryAndName(
Constant.APPLICATION_PROPERTIES_CATEGORY_AUDIT_LOGGING, Constant.APPLICATION_PROPERTIES_AUDIT_LOGGING);
if (applicationProperties.isPresent()) {
isLoggingEnabled = Constant.CONSTANT_Y.equalsIgnoreCase(applicationProperties.get().getValue());
}
return isLoggingEnabled;
}
(Iは、コンフィギュレーションクラスにデバッグポイントを置くことによって、それをチェックします) autowired applicationPropertiesDataService bean nullです。どんな助けもありがとう。ありがとう。
:あなたはこれを行うことができます。 ApplicationPropertiesDataServiceのクラス定義も表示する – KayV