我试图部署一个最小的Vaadin / SpringBoot </跨度> 将应用程序作为WAR文件放入独立的Tomcat中。
如果我运行gradle vaadinRun并在localhost:8080下访问,那么一切都有效,但是创建了WAR:‘com.somecompany.hello-vaadin’ version =‘0.0.1-SNAPSHOT’}
申请插件:‘战争’
战争{ baseName =‘hello-vaadin’ version =‘1.0’}
springBoot </跨度> { mainClass锟
最后,我设法让它发挥作用。这是如何:
MyApplication.java
package com.somecompany; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class MyApplication { public static void main(String[] args) throws Exception { SpringApplication.run(MyApplication.class, args); } }
MyServletInitializer.java
package com.somecompany; import org.springframework.boot.web.support.SpringBootServletInitializer; import org.springframework.boot.builder.SpringApplicationBuilder; public class MyServletInitializer extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { return builder.sources(MyApplication.class); } }
MyConfiguration.java
package com.somecompany; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Bean; @Configuration public class MyConfiguration { @Bean public String myLabelString() { return "Hello World Bean!"; } }
HelloWorldUI.java
package com.somecompany; import com.vaadin.spring.annotation.SpringUI; import com.vaadin.server.VaadinRequest; import com.vaadin.ui.UI; import org.springframework.beans.factory.annotation.Autowired; import com.vaadin.ui.Label; @SpringUI public class HelloWorldUI extends UI { @Autowired String helloWorldString; @Override protected void init(VaadinRequest request) { if (helloWorldString != null) { setContent(new Label(helloWorldString)); } else { setContent(new Label("Injection does not work!")); } } }
的build.gradle
plugins { id 'com.devsoap.plugin.vaadin' version '1.2.1' id 'org.springframework.boot' version '1.5.3.RELEASE' } apply plugin: 'war' war { baseName = 'hellovaadin' } springBoot { mainClass = 'com.somecompany.MyApplication' }
然后用 gradle build 我构建WAR文件,然后将其复制到 webapps 我的tomcat实例的文件夹。
gradle build
webapps
我通过展示如何注入/自动装配bean来扩展该示例。