使用Spring Boot的远程Tomcat和Vaadin

时间:2018-09-04 10:11:16

标签: spring spring-boot tomcat vaadin8

我有一个带有Spring Boot的Vaadin项目,并且正在maven中构建.war并将其部署在远程Tomcat中。 当我尝试转向服务器时,在浏览器中得到404并显示以下堆栈跟踪信息:

javax.servlet.ServletException: com.vaadin.server.ServiceException: com.vaadin.server.ServiceException: ru.lanit.asutd.asutdws.webpage.AdminPanel doesn't have a public no-args constructor
    at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:447) ~[vaadin-server-8.3.1.jar:8.3.1]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[servlet-api.jar:na]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292) [catalina.jar:8.0.47]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.47]
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-websocket.jar:8.0.47]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.47]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207) [catalina.jar:8.0.47]
    at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.3.16.RELEASE.jar:4.3.16.RELEASE]
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.3.16.RELEASE.jar:4.3.16.RELEASE]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240) [catalina.jar:8.0.47]

似乎AdminPanel的创建没有超出Spring的上下文,但是我不确定,我也不知道如何解决此问题。

文件:

Application.java

@SpringBootApplication
@EnableAutoConfiguration
@Configuration
public class Application extends SpringBootServletInitializer {

    private static Class<Application> applicationClass = Application.class;

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder app) {
        return app.sources(applicationClass);
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}

AdminPanel.java

@SuppressWarnings("serial")
@SpringUI(path = "/")
@SpringViewDisplay
public class AdminPanel extends UI implements ViewDisplay {

    @WebServlet(value = "/*", asyncSupported = true)
    @VaadinServletConfiguration(productionMode = false, ui = AdminPanel.class)
    public static class Servlet extends SpringVaadinServlet {
    }

    private SpringNavigator navigator;

    public AdminPanel(SpringNavigator navigator, Authentication authentication) {
        this.navigator = navigator;
        this.AUTH = authentication;
    }

    public static Authentication AUTH;
    private VerticalLayout contentPanel = new VerticalLayout();
    private MenuBar bar = new MenuBar();
    HorizontalLayout topBar = new HorizontalLayout();

    private final MenuBar.Command queue = menuItem -> navigator.navigateTo(QueueView.NAME);
    private final MenuBar.Command externalSystem = menuItem -> navigator.navigateTo(ExternalSystemView.NAME);
    private final MenuBar.Command synhronizedClassifier = menuItem -> navigator.navigateTo(
        SynhronizedClassifierView.NAME);
    private final MenuBar.Command sharedClassifier = menuItem -> navigator.navigateTo(ExternalClassifierView.NAME);

    @Override
    protected void init(VaadinRequest request) {
        settingNavigator();
        settingView();
    }

    private void settingView() {
        contentPanel.setMargin(false);
        contentPanel.setSpacing(false);
        contentPanel.setSizeFull();
        bar.addItem("Очередь", queue);
        bar.addItem("Внешние системы", externalSystem);
        bar.addItem("Синхронизирующиеся классификаторы", synhronizedClassifier);
        bar.addItem("Внешние классификаторы", sharedClassifier);

        topBar.setWidth("100%");
        Button logout = new Button("Выход");
        logout.addClickListener(click -> {
            getSession().close();
            Page.getCurrent().reload();
        });
        topBar.addComponents(bar, logout);
        topBar.setComponentAlignment(logout, Alignment.BOTTOM_RIGHT);

        VerticalLayout vl = new VerticalLayout();
        vl.setMargin(false);
        vl.setSizeFull();
        vl.addComponents(topBar, contentPanel);
        vl.setExpandRatio(contentPanel, 0.9f);
        this.setContent(vl);
    }

    private void settingNavigator() {
        navigator.addView(LoginPanel.NAME, LoginPanel.class);
        navigator.addView(QueueView.NAME, QueueView.class);
        navigator.addView(ExternalClassifierView.NAME, ExternalClassifierView.class);
        navigator.addView(SynhronizedClassifierView.NAME, SynhronizedClassifierView.class);
        navigator.addView(ExternalSystemView.NAME, ExternalSystemView.class);

        getPage().getCurrent().addUriFragmentChangedListener(
                (Page.UriFragmentChangedListener) event -> router());
        router();
    }

    private void router() {
        if (getSession().getAttribute("user") != null) {
            navigator.navigateTo(QueueView.NAME);
        } else {
            navigator.navigateTo(LoginPanel.NAME);
        }
    }

    @Override
    public void showView(View view) {
        if (view.getViewComponent().getClass().getSimpleName().equals("LoginPanel")) {
            topBar.setVisible(false);
        } else {
            topBar.setVisible(true);
        }
        contentPanel.removeAllComponents();
        contentPanel.addComponent((Component) view);
    }
}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>ru.lanit.asutd</groupId>
    <artifactId>asutd-ws</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>asutd-ws</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.12.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <vaadin.version>8.3.1</vaadin.version>
        <asutd.version>7.6-SNAPSHOT</asutd.version>
        <start-class>ru.lanit.asutd.asutdws.Application</start-class>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.vaadin</groupId>
                <artifactId>vaadin-bom</artifactId>
                <version>${vaadin.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>log4j-over-slf4j</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- ASUTD -->
        <!-- Web Services -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <!--<scope>provided</scope>-->
        </dependency>
        <dependency>
            <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
        </dependency>

        <!-- Поддержка импорта внутри xsd -->
        <dependency>
            <groupId>org.apache.ws.xmlschema</groupId>
            <artifactId>xmlschema-core</artifactId>
            <version>2.2.3</version>
        </dependency>

        <dependency>
            <groupId>com.vaadin</groupId>
            <artifactId>vaadin-spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.reflections</groupId>
            <artifactId>reflections</artifactId>
            <version>0.9.10</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
                <version>1.6</version>
                <executions>
                    <execution>
                        <id>xjc</id>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <schemaDirectory>${project.basedir}/src/main/resources/xsd</schemaDirectory>
                    <outputDirectory>${project.basedir}/src/main/java</outputDirectory>
                    <arguments>-no-header</arguments>
                    <clearOutputDir>false</clearOutputDir>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

0 个答案:

没有答案