@ImportResource
に関連する作品を作るのに問題がありPropertySourcesPlaceholderConfigurer
ます。私が見つけることができる最も近いのはこの質問ですが、どうすればそれを機能させることができるのか理解できません。
これが私の構成クラスです:
@Configuration
@ComponentScan(basePackages = "com.example")
@EnableWebMvc
@EnableScheduling
@EnableAsync
@ImportResource("classpath:/config/webservices.xml")
public class AppConfig {
@Bean
public static PropertySourcesPlaceholderConfigurer properties(Environment environment) throws IOException {
String env = StringUtils.defaultIfBlank(environment.getProperty("env"), "local");
PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
Resource[] allResources = generateListOfPropertiesFiles(env);
configurer.setLocations(allResources);
configurer.setIgnoreResourceNotFound(true);
return configurer;
}
:
}
構成ファイルのセットアップのために、このかなり複雑なアプローチが必要です。
言及は次の/config/webservices.xml
ようになります。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:client id="sessionControl"
serviceClass="com.service.schemas.work1_2.SessionControl" address="${endpoint.sessionControl}">
<jaxws:features>
<bean class="org.apache.cxf.feature.LoggingFeature" />
</jaxws:features>
</jaxws:client>
</beans>
endpoint.sessionControl
ファイルの 1 つで定義され.properties
ます。
私が理解している限り、XMLはPropertySourcesPlaceholderConfigurer
存在する前に解析および評価されるため、プレースホルダーを置き換えるコードはありません。しかし、Spring の内部に、後ですべてのプロパティが読み取られたときに XML を解析する必要があることを理解させるにはどうすればよいでしょうか? 使い方は正しい@ImportResource
ですか?Spring に何を提供する必要がありますか? それとも、それを機能させるためのかなり簡単なトリックはありますか?
私は、Spring のこの部分で Bean ライフサイクルと Bean ファクトリを使用する初心者です。すべてがうまく機能していることにいつも驚かされます (まあ、通常は)...
--EDIT-- @PostConstruct
でアドレスを設定しようとしましたが、うまくいきません。それは常に "${...}" に戻っています:
@Inject
private SessionControl sessionControl;
@Value("${endpoint.sessionControl}")
private String endpointSessionControl;
@PostConstruct
public void postConstruct() {
((Client) sessionControl).getConduit().getTarget().getAddress().setValue(endpointSessionControl);
((Client) sessionControl).getEndpoint().getEndpointInfo().setAddress(endpointSessionControl);
}