我試圖將一個最小的Vaadin/SpringBoot應用程序作爲WAR文件部署到獨立的Tomcat中。如果我跑gradle vaadinRun
和訪問localhost:8080
下,但創建與gradle war
WAR文件,然後複製它變成我的Tomcat結果的webapps文件夾中404不幸的是Tomcat的日誌不顯示任何東西作爲WAR部署Vaadin/SpringBoot
一切正常。嘗試通過localhost:8080/hello-vaadin
訪問。
這裏是應用類本身:
package com.somecompany;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.boot.autoconfigure.*;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.boot.web.servlet.ServletComponentScan;
import com.vaadin.spring.annotation.EnableVaadin;
@ServletComponentScan
@SpringBootApplication
@EnableVaadin
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) throws Exception {
configureApplication(new SpringApplicationBuilder()).run(args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return configureApplication(builder);
}
private static SpringApplicationBuilder configureApplication(SpringApplicationBuilder builder) {
return builder.sources(Application.class);
}
}
這是對應的UI類:
package com.somecompany;
import com.vaadin.annotations.Theme;
import com.vaadin.spring.annotation.SpringUI;
import com.vaadin.server.VaadinRequest;
import com.vaadin.ui.UI;
import com.vaadin.ui.Grid;
import org.springframework.beans.factory.annotation.Autowired;
import com.vaadin.ui.Label;
@SpringUI
@Theme("valo")
public class HelloWorldUI extends UI {
@Autowired
public HelloWorldUI() {
}
@Override
protected void init(VaadinRequest request) {
setContent(new Label("Hello World!"));
}
}
最後我gradle這個腳本:
plugins {
id "java"
id "com.devsoap.plugin.vaadin" version "1.2.4"
id "org.springframework.boot" version "1.5.7.RELEASE"
}
jar {
baseName = 'com.somecompany.hello-vaadin'
version = '0.0.1-SNAPSHOT'
}
apply plugin: 'war'
war {
baseName = 'hello-vaadin'
version = '1.0'
}
springBoot {
mainClass = 'com.somecompany.Application'
}
bootRepackage {
mainClass = 'com.somecompany.Application'
}
repositories {
jcenter()
mavenCentral()
maven { url "http://oss.sonatype.org/content/repositories/vaadin-snapshots/" }
maven { url 'https://repo.spring.io/libs-release' }
maven { url "https://repository.jboss.org/nexus/content/repositories/releases" }
}
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
}
通過教程去後在教程之後,必須有一些我忽略的東西。但是,我不明白這個問題會是什麼?
任何提示高度讚賞!
作爲maven用戶,我需要spring-boot-maven-plugin,也許還有一個等價的gradle呢? – mrkernelpanic
@Jay是的,我可以從經理頁面看到應用程序。 – Tobias
@mrkernelpanic這應該在第四行org.springframework.boot插件中完成。 – Tobias