Vaadin 14.3.6-服务器连接丢失,尝试重新连接

时间:2020-09-28 10:51:15

标签: java spring spring-boot spring-security vaadin

我对vaadin有疑问。上载按钮不起作用。请查看代码,您可以检测到错误。服务器连接断开,显示数据时也会出现尝试重新连接的情况。

@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Bean
    public PasswordEncoder getPasswordEncoder(){
        return new BCryptPasswordEncoder();
    }
    
    private UserDetailsServiceImpl userDetailsService;
    
    public WebSecurityConfig(final UserDetailsServiceImpl userDetailsService) {
        this.userDetailsService = userDetailsService;
    }
    
    @Override
    protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(userDetailsService);
    }
    
    @Override
    protected void configure(final HttpSecurity http) throws Exception {
        http.csrf().disable();
        http.headers().disable();
        http.authorizeRequests()
                .antMatchers("/hello").authenticated()
                .antMatchers("/for-admin").hasRole("ADMIN")
                .antMatchers("/upload").permitAll()
                .antMatchers("/gallery").hasAnyRole("ADMIN","USER")
                .antMatchers("/for-user").hasRole("USER")
                .and()
                .formLogin().defaultSuccessUrl("/hello");
    }
}

@Route("upload")
class UploadGui extends VerticalLayout {

    private ImageService imageService;

    public UploadGui(ImageService imageService) {
        this.imageService = imageService;

        Label label = new Label();
        TextField textField = new TextField();
        Button button = new Button("upload");
        button.addClickListener(clickEvent ->
        {
            String uploadImage = imageService.uploadFileAndSaveToDb(textField.getValue());
            Image image = new Image(uploadImage, "empty");
            label.setText("Upload complete");
            add(label);
            add(image);
        });
    
        add(textField);
        add(button);
    }
}

当我转到端点/上载时,此消息弹出。我没有点击按钮。 Imageservice还可以,在一切正常之前,我没有在这些类中进行任何更改。添加与图像无关的新类时出现了问题。

当我转到端点时,上载控制台显示this。 该按钮不响应单击。

0 个答案:

没有答案