3

我正在尝试将 BlazeDS 添加到 Spring Boot 应用程序中。为此,我在配置中添加了“MessageBrokerServlet”:

@Bean
public ServletRegistrationBean messageBrokerRegistration()
{
    ServletRegistrationBean registration = new ServletRegistrationBean(new MessageBrokerServlet(), "/messagebroker/*");
    Map<String,String> params = Maps.newHashMap();
    params.put( "services.configuration.file", "/WEB-INF/flex/services-config.xml" );
    registration.setInitParameters(params);
    return registration;
}

servlet 被加载,但在运行时失败:

MessageBrokerServlet in application 'undefined' failed to initialize due to runtime exception:   
Exception: flex.messaging.config.ConfigurationException: Please specify a 
valid 'services.configuration.file' in web.xml. You specified '{0}'.
This is not a valid file system path reachable via the app server and 
is also not a path to a resource in your J2EE application archive.

翻阅 BlazeDS 的源代码,我看到最后,代码使用了ServletContext#getResourceAsStream(path). 如何使 Spring Boot 中的嵌入式 tomcat 在该调用中返回某些内容?

我正在使用使用嵌入式 Tomcat 7.0.54 的 Spring Boot 1.1.1

4

2 回答 2

0

Servlet 上下文资源至少应该在战争中工作。将它们src/main/webapp插入(用于标准构建布局)。

于 2014-07-12T16:47:42.200 回答
0

我最近能够使用以下方法做到这一点:

@Lazy
@Bean(name="messageBroker")
public MessageBrokerFactoryBean messageBrokerFactoryBean() {
    MessageBrokerFactoryBean messageBrokerFactory = new MessageBrokerFactoryBean();
    messageBrokerFactory.setServicesConfigPath("classpath:/flex/services-config.xml");
    return  messageBrokerFactory;
}

services-config.xml(和我的其他 flex 配置文件)在 src/main/resources/flex 中

希望这个希望别人!

于 2016-01-28T17:52:12.030 回答