Ban*_*ane 6 glassfish-3 spring-tool-suite spring-boot
正如这里提到的,我有一点时间让我的小型Spring-Boot项目"正确"部署到Glassfish.它使用嵌入式Tomcat运行良好,但是一旦我尝试将其移动到我的组织环境(Glassfish 3.1.2)中,我就会遇到一些奇怪的行为.
认为这是我的代码,我回到了经过时间考验的"Hello World" - 方法,并在Spring的博客上建立了一个超级基本的应用程序.
当我一起去的时候,我确实做了一些非常小的偏差,但是根本没有任何应该影响这个应用程序的东西.
我发现的唯一一个主要偏差是我发现我无法从"spring-boot-starter-web"中排除"spring-boot-starter-tomcat" - 当我尝试这个时,我在STS中遇到了2个错误"Markers" "-标签:
The project was not built since its build path is incomplete. Cannot find the class file for javax.servlet.ServletContext. Fix the build path then try building this project
The type javax.servlet.ServletContext cannot be resolved. It is indirectly referenced from required .class files Application.java
Run Code Online (Sandbox Code Playgroud)
如果我清理了STS项目,然后运行Maven Clean,更新,安装Install目标会出现以下错误:
Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project test: Compilation failure [ERROR] /Users/brandon_utah/Utah Development/sts_workspaces/NidTools Rebooted/test/src/main/java/test/Application.java:[13,8] cannot access javax.servlet.ServletException [ERROR] class file for javax.servlet.ServletException not found
Run Code Online (Sandbox Code Playgroud)
所以我做的是包含这种依赖(我在其他几个SpringBoot资源中提到过):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
在这个部署好的嵌入式Tomcat中,它确实部署到我的Glassfish(本地安装) - 但是有一大堆(大约六个)类似于这个错误:
2014-04-03T16:23:48.156-0600|SEVERE: Class [ Lorg/springframework/jdbc/datasource/embedded/EmbeddedDatabase; ] not found. Error while loading [ class org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration ]
Run Code Online (Sandbox Code Playgroud)
他们中的大多数都是严重的,但我也有一些警告:
2014-04-04T06:57:35.921-0600|WARNING: Error in annotation processing: java.lang.NoClassDefFoundError: org/springframework/batch/core/configuration/annotation/BatchConfigurer
Run Code Online (Sandbox Code Playgroud)
除了我没有在我的项目中的任何地方引用任何这些缺少的类(除了Spring Boot本身可能引用的类).
此外,该应用程序没有按预期工作.如果我点击了RestController,我确实按照我的预期渲染了我的页面 - 但是如果我在控制器的方法中放入任何类型的System.out或Logger.log语句,那行代码似乎永远不会被执行; 从各方面来看,它都被忽略了.
为了演示这个问题,在我的示例应用程序的RestController中,我创建了一个静态计数器.然后在GET- /方法中我增加该计数器和System.out.println它的值.我还将值作为Response的一部分返回.
再次,从用户的角度来看,它似乎正在工作:屏幕呈现"Hello World",在括号中显示计数器的值.我刷新窗口,计数器递增.但STS控制台中没有任何内容.如果我导航到应用程序的Glassfish日志,那么也没有.没有.纳达.压缩.据我所知,有些东西神秘地吃任何记录任何东西的尝试.
为了增加这个谜团,如果我将一个System.out添加到SpringBootServletInitializer#configure(),它确实会进入控制台.但是如果我在我的RestController中声明一个构造函数并在那里包含一个System.out,那么它就不会进入控制台.为了更好地衡量,我甚至尝试在构造函数中包含一个System.err,并在方法中包含一个Logger.getAnonymousLogger.severe; 这些都不会导致任何结果.
我应该注意,这也使用外部Tomcat按预期部署和运行.
我非常感谢任何输入,因为我不太可能说服我的组织将其部署到Tomcat,也不可能使用嵌入式Tomcat方法(由于政治和压倒性的现有Glassfish环境).
这已在这里得到解答:https ://stackoverflow.com/a/29438821/508247
Glassfish 3.1.X 中存在一个错误。您需要将其包含metadata-complete="true"在 web.xml 根元素中。
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1"
metadata-complete="true"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
</web-app>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7518 次 |
| 最近记录: |