在彈簧引導的vaadin項目中使用彈簧安全性時出現問題。所以我使用一個PdfViewer插件來顯示PDF文件。但是,我發現了以下錯誤消息:404使用彈簧引導與vaadin時的js文件
error:"Not Found"
message:"No message available"
path:"/APP/PUBLISHED/pdf.worker.js"
status:404
和我的春天的安全配置是這樣的:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.headers()
.defaultsDisabled()
.frameOptions().sameOrigin().and()
.csrf().disable() // Use Vaadin's CSRF protection
.authorizeRequests().antMatchers("/").permitAll()
.antMatchers("/vaadinServlet/HEARTBEAT/**").permitAll()
.antMatchers("/vaadinServlet/UIDL/**").permitAll()
.antMatchers("/vaadinServlet/APP/PUBLISHED/**").permitAll()
.antMatchers("login?debug").permitAll()
.antMatchers("/#!pwdreset/*").permitAll()
.antMatchers("/pwdreset/*").permitAll()
.and()
.authorizeRequests()
.and()
.formLogin().loginPage("/#!login").permitAll()
.and()
.logout().logoutUrl("/#!login?logout").logoutSuccessUrl("/").permitAll().and()
.sessionManagement().sessionFixation().newSession();
}
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/resources/**", "/VAADIN/**");
}
所以,檢查在Chrome加載的文件,我看到一個文件夾/vaadinServlet/APP/PUBLISHED/並且有所有需要的文件。
使用沒有Spring Security的插件工作正常,所以任何人有任何想法?
更新
它似乎並不涉及到Spring Security的,因爲我得到了類似的行爲,而在一個新的簡單的項目測試附加組件。這似乎是與春季啓動問題。
要重現此問題,您需要(full project for download):
- 基本春天開機+ vaadin應用骨架
- 簡單的PDF和下
/webapp/files
- PdfViewer add-on在你的POM和視窗元件
- 下面編譯簡單的用戶界面
@Theme("mytheme")
@SpringUI
@Widgetset("org.test.AppWidgetSet")
public class MyUI extends UI {
@Override
protected void init(VaadinRequest vaadinRequest) {
final VerticalLayout layout = new VerticalLayout();
String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath();
File file = new File(basepath.concat("/files/test.pdf"));
if (file.exists()) {
PdfViewer pdfViewer = new PdfViewer(file);
Label info = new Label("File was found!");
layout.addComponents(info, pdfViewer);
} else {
Label info = new Label("no file found!");
layout.addComponent(info);
}
setContent(layout);
}
}
- 打開鉻&開發人員工具與
Network
選項卡選中,訪問該應用程序,你應該看到一個請求pdf.worker.js
失敗。
你能提供一個[SSCCE(http://sscce.org)來重現問題了嗎?沒有什麼奇特的,只是一個最小的POM,UI,彈簧引導配置和發射器(主類)產生這個錯誤。我沒有看到你的配置有什麼問題,也許你可以將所有靜態資源路徑移動到'configure'方法中的'ignore'匹配器列表,但它不應該是一個問題。我有一個類似的設置,但我的工作正常,所以沒有重現它會很難理解(至少對我來說) – Morfic
@Morfic我剛剛更新了我的問題,因爲它似乎是與春季啓動問題,它沒有與春季安全有關。雖然創建一個例子,我得到了像我的項目一樣的錯誤。可能你對如何解決這個問題有任何想法。 –