在这里给出的例子中:
https://vaadin.com/docs/framework/application/application-resources.html
images-folder放在应用程序的WEB-INF目录中.
在我的Vaadin Spring应用程序中,我没有WEB-INF目录,因此我将images文件夹放在"resources"文件夹中.这里是"src/main/resources"里面和"target"里面的文件夹结构:
问题是我的应用程序无法访问那里的图像.我总是得到相同的"找不到文件"例外.
我尝试了不同的路径描述,其中包括以下内容:
VaadinService.getCurrent().getBaseDirectory().getAbsolutePath() + "images/pic.png"
VaadinService.getCurrent().getBaseDirectory().getAbsolutePath() + "/classes/images/pic.png"
VaadinService.getCurrent().getBaseDirectory().getAbsolutePath() + "/target/classes/images/pic.png"
VaadinService.getCurrent().getBaseDirectory().getAbsolutePath() + "/applicationName/target/classes/images/pic.png"
Run Code Online (Sandbox Code Playgroud)
......什么都没有用!!
如何使我的Vaadin Spring应用程序可以访问这些图像?
在我的Vaadin spring启动应用程序中,我需要将文件上传到服务器并将其保存在那里.
将文件本地上传到我的桌面工作正常,但我想将应用程序部署到服务器,所以我想将上传的文件保存在相对于我的应用程序的基本路径的目录中.
我创建了一个名为"input_files"的文件夹作为根应用程序文件夹(applicationName - > input_files)的直接子项.上传文件时,应该将文件的内容写入此"input_files"文件夹中新创建的文件.
码:
class FileReceiver implements Upload.Receiver, Upload.SucceededListener {
private File file;
public OutputStream receiveUpload(String filename, String mimeType) {
String basePath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath();
FileOutputStream fileOutputStream;
try {
//this line would work:
//file = new File("/Users/username/Desktop/input_files/" + filename);
//this line does not work:
file = new File(basePath + "/input_files/" + filename);
fileOutputStream = new FileOutputStream(file);
labelFilename.setCaption(filename);
}
catch (final java.io.FileNotFoundException e) {
new Notification("Could not open file", e.getMessage(), Notification.Type.ERROR_MESSAGE).show(Page.getCurrent());
return null;
}
return fileOutputStream;
}
public …Run Code Online (Sandbox Code Playgroud) 我们正在使用 Vaadin 19 Fusion 构建一个网络应用程序,我正在学习本教程:https : //vaadin.com/docs/latest/fusion/security/spring-login (我选择了 V19+ Docs,然后是 Fusion)
在教程中有一个参考,VaadinWebSecurityConfigurerAdapter用于设置 Spring 的安全性,但是这个类在类路径上不可用。我曾尝试从 start.vaadin.com 下载一个普通的入门项目 (v19),但在这里我也无法使用VaadinWebSecurityConfigurerAdapter.
v19 中是否有替代方案,或者我是否缺少依赖项?我有与启动项目相同的依赖树,所以我假设 pom 是正确的。
我正在尝试重现官方Vaadin Dashboard Demo的简化版本,但我使用Spring Boot来管理依赖项.
在DashboardServlet.java文件中,您将找到以下代码:
public class DashboardServlet extends VaadinServlet {
@Override
protected final void servletInitialized() throws ServletException {
super.servletInitialized();
getService().addSessionInitListener(new DashboardSessionInitListener());
}
}
Run Code Online (Sandbox Code Playgroud)
该演示使用的是定制的servlet.
问题:如何在Spring Boot中实现?如何让Spring Boot注入我的自定义servlet类?
我已经下载了vaadin面包店应用程序的源代码。它使用商业组件。但是,如果我从代码中删除了这些组件(如果可能的话),我可以使用代码并在不违反任何许可的情况下分发它吗?
谢谢