Spring Boot + GWT嵌入式配置 [英] Spring Boot + GWT embedded configuraiton
问题描述
我想配置Spring Boot嵌入式Servlet容器+ GWT。我想要的方式是创建一个jar / war文件,它只包含编译后的gwt文件&静态资源。我想从lib / *和classpath的配置文件中加载jar。
我找不到任何工作示例。实际上有一个, https://github.com/Ekito/spring-boot-gwt ,但所有依赖和配置仍然处于战争状态。
有人可以提出一个解决方案吗?
```
<! - POM - >
< modelVersion> 4.0.0< / modelVersion>
< groupId> fr.ekito.gwt< / groupId>
< artifactId> gwt-boot< / artifactId>
< version> 0.0.1-SNAPSHOT< / version>
<包装> jar< / packaging>
< name> Ekito Spring Boot GWT WebApp< / name>
< parent>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-parent< / artifactId>
< version> 1.2.5.RELEASE< / version>
< / parent>
<属性>
< project.build.sourceEncoding> UTF-8< /project.build.sourceEncoding>
< project.reporting.outputEncoding> UTF-8< /project.reporting.outputEncoding>
< start-class> fr.ekito.gwt.server.ServerApplication< / start-class>
< java.version> 1.7< /java.version>
< googleGin> 2.1.2< / googleGin>
< outputFolder> $ {project.build.directory} / $ {artifactId}< / outputFolder>
< / properties>
<依赖关系>
< dependency>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-web< / artifactId>
<排除项>
<排除>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-tomcat< / artifactId>
< /排除>
< /排除>
< /依赖关系>
< dependency>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-starter-undertow< / artifactId>
<排除项>
<排除>
< groupId> io.undertow< / groupId>
< artifactId> undertow-websockets-jsr< / artifactId>
< /排除>
< /排除>
< /依赖关系>
< dependency>
< groupId> org.hibernate< / groupId>
< artifactId> hibernate-validator< / artifactId>
< /依赖关系>
< dependency>
< groupId> com.google.gwt< / groupId>
< artifactId> gwt-user< / artifactId>
< version> $ {gwtVersion}< / version>
< /依赖关系>
< dependency>
< groupId> com.google.gwt.inject< / groupId>
< artifactId> gin< / artifactId>
<版本> $ {googleGin}< / version>
< /依赖关系>
< /依赖关系>
< build>
< plugins>
< plugin>
< groupId> org.springframework.boot< / groupId>
< artifactId> spring-boot-maven-plugin< / artifactId>
<配置>
< mainClass> $ {start-class}< / mainClass>
< layout> ZIP< / layout>
< / configuration>
< / plugin>
< plugin>
< groupId> org.codehaus.mojo< / groupId>
< artifactId> gwt-maven-plugin< / artifactId>
< version> $ {gwtVersion}< / version>
<执行次数>
<执行>
<目标>
< goal>编译< / goal>
< /目标>
< /执行>
< /执行次数>
<配置>
< runTarget> GwtWebApp.html< / runTarget>
< persistentunitcachedir> $ {project.build.directory}< / persistentunitcachedir>
< deploy> $ {project.build.directory} / gwt-deploy< / deploy>
< webappDirectory> $ {project.build.directory} / classes / public< / webappDirectory>
< / configuration>
< / plugin>
< / plugins>
< / build>
```
我的项目结构与原始项目相同, https://github.com/Ekito/spring-boot-gwt ,除了一些小的变化:
- 而不是 webapp 我有 src / main / resources / public 文件夹,而html& css文件存在。
- 不需要web.xml文件,spring-boot照顾它。
- 不需要WEB-INF文件夹。
因此,我有一个可运行jar,但是由org.springframework.boot.loader.PropertiesLauncher运行。单个罐子按预期工作,Tomcat不像这里所说的那样工作: http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-developing-web-applications.html# boot-features-jsp-restrictions 。
另外,我可以将lib文件夹移动到jar文件的外部,但我为了设置 loader.path
属性,我需要把它放到jar文件里面的application.properties中。我应该可以使用-Dloader.path但无效。
我会和春季队一起检查。但到目前为止,这是有希望的。
I want to configure Spring Boot Embedded Servlet Container + GWT. The way I want is either create a jar/war file that just contains the compiled gwt files & static resources. I want to load jars from lib/* and config files from classpath.
I couldn't find any working example. There is one actually, https://github.com/Ekito/spring-boot-gwt, but all the dependencies and configs are still in the war.
Can someone suggest a solution ?
After long search & test, here is the solution that I come up with:
```
<!-- POM -->
<modelVersion>4.0.0</modelVersion>
<groupId>fr.ekito.gwt</groupId>
<artifactId>gwt-boot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Ekito Spring Boot GWT WebApp</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.5.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<start-class>fr.ekito.gwt.server.ServerApplication</start-class>
<java.version>1.7</java.version>
<gwtVersion>2.6.0</gwtVersion>
<googleGin>2.1.2</googleGin>
<outputFolder>${project.build.directory}/${artifactId}</outputFolder>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
<exclusions>
<exclusion>
<groupId>io.undertow</groupId>
<artifactId>undertow-websockets-jsr</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwtVersion}</version>
</dependency>
<dependency>
<groupId>com.google.gwt.inject</groupId>
<artifactId>gin</artifactId>
<version>${googleGin}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>${start-class}</mainClass>
<layout>ZIP</layout>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>${gwtVersion}</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<runTarget>GwtWebApp.html</runTarget>
<persistentunitcachedir>${project.build.directory}</persistentunitcachedir>
<deploy>${project.build.directory}/gwt-deploy</deploy>
<webappDirectory>${project.build.directory}/classes/public</webappDirectory>
</configuration>
</plugin>
</plugins>
</build>
```
my project structure is is same with original project, https://github.com/Ekito/spring-boot-gwt, except some little changes:
- Instead of webapp folder, I have src/main/resources/public folder, and html & css file is there.
- No need for web.xml file, spring-boot take care of it.
- No need for WEB-INF folder.
As a result, I have a runable jar, but run by org.springframework.boot.loader.PropertiesLauncher. Single jar works as expected, Tomcat doesnt work as stated here: http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-developing-web-applications.html#boot-features-jsp-limitations.
Also, I can move the lib folder outside the jar file, but I in order to set the loader.path
property, I need to put it to application.properties inside the jar file. I should be able to use -Dloader.path but didn't work.
I'll check with spring team. But so far, it's promising.
这篇关于Spring Boot + GWT嵌入式配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!