我有两个在 HandlerConfiguration.java 中定义的 GenericHandlerResolver bean,例如:
@Bean(autowire = Autowire.BY_NAME)
@Scope(value = "prototype")
public GenericHandlerResolver defaultHandlerResolver() {
return new GenericHandlerResolver(){{
setHandlers(new ArrayList<Handler>(){{
add(loggingHandler());
add(sessionHandler());
}});
}};
}
@Bean(autowire = Autowire.BY_NAME)
@Scope(value = "prototype")
public GenericHandlerResolver maskingHandlerResolver() {
return new GenericHandlerResolver(){{
setHandlers(new ArrayList<Handler>(){{
add(maskingLoggingHandler());
add(sessionHandler());
}});
}};
}
然后我想将两个不同的 bean 自动装配到 WebServiceConfiguration.java 中,并在几十个 JaxWsPortProxyFactoryBean bean 中使用它们,例如:
@Configuration
public class WebServiceConfiguration {
...
public Integer paymentServiceTimeout;
@Bean @DependsOn("applicationProperties")
public Map<String, Object> paymentServiceProperties(){
return new HashMap<String, Object>(){
{put(timeoutKey, paymentServiceTimeout);}
};
}
...
// Logging handler resolver:
/*@Autowired
protected GenericHandlerResolver defaultHandlerResolver;*/
// Logging handler resolver that will mack Credit Cards:
@Autowired
protected GenericHandlerResolver maskingHandlerResolver;
...
@Bean
@Lazy
@DependsOn("applicationProperties")
public JaxWsPortProxyFactoryBean paymentServicePort() throws Exception {
JaxWsPortProxyFactoryBean jppfb = new JaxWsPortProxyFactoryBean() {{
setServiceInterface(PaymentServicePortType.class);
setWsdlDocumentUrl(new URL(paymentServiceEndpoint + "?wsdl"));
setServiceName("PaymentService");
setEndpointAddress(paymentServiceEndpoint);
setCommonProperties(this,
paymentServiceProperties(),
maskingHandlerResolver,
LEGACY_NAMESPACE);
}};
jppfb.afterPropertiesSet();
return jppfb;
}
protected void setCommonProperties(JaxWsPortProxyFactoryBean bean,
Map<String, Object> customProperties,
GenericHandlerResolver handlerResolver,
String namespace) {
bean.setMaintainSession(false);
bean.setLookupServiceOnStartup(false);
bean.setCustomProperties(customProperties);
bean.setHandlerResolver(handlerResolver);
bean.setNamespaceUri(namespace);
}
我的问题是这在 XML 配置中有效,但是现在我将其移至 javaConfig,如果我在 WebServiceConfiguration.java 中有多个 GenericHandlerResolver,则处理程序不起作用(没有日志记录),但我没有收到任何错误消息,所以我不知道发生了什么。