I took a lookat the old Vaadin 14 Application Lifecycle Documentation. There you could configure your own Servlets, Services and Sessions.
I kinda need that, because I need to add on top of the regular Vaadin Sessions. Simply defining my own Classes and setting them up correctly doesnt seem to do the trick.
I also already tried defining them as its own @Bean in my Application Class, but that only gave me some Error Messages during Startup.
My Application.java:
package com.marcobsidian.briefmarken;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration;
import com.marcobsidian.briefmarken.base.application.ApplicationServlet;
import com.vaadin.flow.component.dependency.NpmPackage;
import com.vaadin.flow.component.page.AppShellConfigurator;
import com.vaadin.flow.server.VaadinServlet;
import com.vaadin.flow.theme.Theme;
/**
* The entry point of the Spring Boot application.
*
* Use the @PWA annotation make the application installable on phones, tablets
* and some desktop browsers.
*
*/
@SpringBootApplication(exclude = ErrorMvcAutoConfiguration.class)
@NpmPackage(value = "@fontsource/nunito-sans", version = "4.5.0")
@Theme(value = "briefmarken")
@NpmPackage(value = "line-awesome", version = "1.3.0")
public class Application implements AppShellConfigurator {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
My ApplicationServlet.java:
package com.marcobsidian.briefmarken.base.application;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import com.vaadin.flow.function.DeploymentConfiguration;
import com.vaadin.flow.server.*;
@WebServlet
public class ApplicationServlet extends VaadinServlet implements SessionInitListener, SessionDestroyListener {
@Override
protected VaadinServletService createServletService(DeploymentConfiguration deploymentConfiguration)
throws ServiceException {
ApplicationService service = new ApplicationService(this, deploymentConfiguration);
service.init();
return service;
}
@Override
public void sessionDestroy(SessionDestroyEvent event) {
//To be continued...
}
@Override
public void sessionInit(SessionInitEvent event) throws ServiceException {
//To be continued...
}
}
My ApplicationService.java:
package com.marcobsidian.briefmarken.base.application;
import com.vaadin.flow.function.DeploymentConfiguration;
import com.vaadin.flow.server.*;
public class ApplicationService extends VaadinServletService {
public ApplicationService(VaadinServlet servlet, DeploymentConfiguration deploymentConfiguration) {
super(servlet, deploymentConfiguration);
}
@Override
protected VaadinSession createVaadinSession(VaadinRequest request) {
return new ApplicationSession(this);
}
}
ApplicationSession.java:
package com.marcobsidian.briefmarken.base.application;
import com.vaadin.flow.internal.CurrentInstance;
import com.vaadin.flow.server.VaadinService;
import com.vaadin.flow.server.VaadinSession;
public final class ApplicationSession extends VaadinSession {
public static ApplicationSession getCurrent() {
return CurrentInstance.get(ApplicationSession.class);
}
public ApplicationSession(VaadinService service) {
super(service);
}
}
Also for the sake of simplicity I removed all for-this-question-irrelevant-things from the classes. There is actually a whole lot going on in these. I know why I want my own Session-Object :)
Tried:
Defining @Bean for VaadinServlet in Application.java
Manually Switching out Service-Class via VaadinService.setCurrent()
Excluding Classes via @SpringBootApplication
Obviously researching a lot but havent found any Vaadin23-Articles about this topic so far
Expected:
- Vaadin uses my custom Objects over VaadinServlet, VaadinServletService and VaadinService, but it never ended up doing that