是否有人使用Vaadin @Push和vaadin-spring-boot-starter以及Vaadin4Spring Security扩展?
以下是与我们项目相关的Vaadin依赖项:
compile 'com.vaadin:vaadin-client-compiled:7.5.8'
compile 'com.vaadin:vaadin-client:7.5.8'
compile 'com.vaadin:vaadin-themes:7.5.8'
compile 'com.vaadin:vaadin-server:7.5.8'
compile 'com.vaadin:vaadin-push:7.5.8'
// Official VaadinSpring Integration
compile("com.vaadin:vaadin-spring-boot-starter:1.0.0")
//Vaadin extentions - in the future more of those will go to official VaadinSpring Integration
compile("org.vaadin.spring.extensions:vaadin-spring-ext-security:0.0.6.RELEASE")
compile("org.vaadin.spring.extensions:vaadin-spring-ext-core:0.0.6.RELEASE")
compile("org.vaadin.spring.extensions:vaadin-spring-ext-boot:0.0.6.RELEASE")
compile("org.vaadin.spring.extensions:vaadin-spring-ext-test:0.0.6.RELEASE")
以下是UI类
上的注释@Theme("mytheme")
@Title(com.test.util.Constants.TITLE)
@EnableOAuth2Client
@SpringUI
@Push
public class MyVaadinUI extends UI {
...
}
并且,Application.java;
@EnableVaadinExtensions
@SpringBootApplication
@EnableConfigurationProperties
@EnableI18N
@EnableEventBus
@RestController
@EnableOAuth2Client
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
@Bean
public RequestContextListener requestContextListener(){
return new RequestContextListener();
}
@Bean
public FilterRegistrationBean hiddenHttpMethodFilter() {
HiddenHttpMethodFilter hiddenHttpMethodFilter = new HiddenHttpMethodFilter();
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
registrationBean.setFilter(hiddenHttpMethodFilter);
return registrationBean;
}
@Bean(name = "messageSource")
public ResourceBundleMessageSource messageSource() {
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename("messages/messages");
logger.debug("Returning messageSource: " + ((messageSource != null) ? messageSource.toString() : "NULL"));
return messageSource;
}
}
我们一打电话 security.login(username.getValue(),password.getValue()); (安全性是org.vaadin.spring.security.VaadinSecurity;)
我们得到以下异常;
16:36:35.272 [http-nio-8080-exec-9]错误cbgcsvviews.login.LoginBox / login在login.org.springframework.beans.factory.BeanCreationException期间发生登录错误:创建名称为&的bean时出错#39; scopedTarget.httpService':范围'请求'当前线程不活动;考虑为这个bean定义一个范围代理,如果你想从一个单例引用它;嵌套异常是java.lang.IllegalStateException:找不到线程绑定请求:您是指在实际Web请求之外的请求属性,还是在最初接收线程之外处理请求?如果您实际上是在Web请求中操作并仍然收到此消息,则您的代码可能在DispatcherServlet / DispatcherPortlet之外运行:在这种情况下,请使用RequestContextListener或RequestContextFilter来公开当前请求。
感谢您提供的任何帮助。
答案 0 :(得分:4)
您正在使用Websockets,它不使用servlet请求,也不会自动激活“请求”范围。
如果您使用@Push(transport = WEBSOCKET_XHR),它应该可以工作,因为websockets通道将仅用于服务器 - >客户端推送和标准HTTP请求将用于客户端 - >服务器消息。