spring 在 weblogic 上启动应用程序部署抛出 404 错误
spring boot application deployment on weblogic throws 404 error
我已经完成了以下配置并尝试了几乎所有找到的解决方案,但没有任何帮助。当我在 war 包中部署 spring 引导应用程序时。 weblogic 日志中没有记录错误,但应用程序抛出 404 错误。
web.xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:root-context.xml</param-value>
</context-param>
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>dev</param-value>
</context-param>
<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>dev</param-value>
</context-param>
<context-param>
<param-name>spring.liveBeansView.mbeanDomain</param-name>
<param-value>dev</param-value>
</context-param>
weblogic.xml
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wls="http://www.bea.com/ns/weblogic/90"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-web-app.xsd">
<wls:weblogic-version>12.1.2.0.0</wls:weblogic-version>
<wls:context-root>/services/userModule/</wls:context-root>
<wls:container-descriptor>
<wls:prefer-application-packages>
<wls:package-name>com.fasterxml</wls:package-name>
<wls:package-name>org.slf4j</wls:package-name>
<wls:package-name>org.springframework.*</wls:package-name>
</wls:prefer-application-packages>
</wls:container-descriptor>
</wls:weblogic-web-app>
application.properties
spring.profiles.default=default
spring.profiles.active=default
spring.liveBeansView.mbeanDomain=default
cms.config.monitor.dir=/server/location/application/artifacts
application.messages.file.name=application-messages
application.config.file.name=application-config
root-context.xml
它包含特定于应用程序的配置。
ApplicationBegin.java
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, JpaRepositoriesAutoConfiguration.class})
public class ApplicationBegin extends SpringBootServletInitializer implements WebApplicationInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(ApplicationBegin.class);
}
public static void main(String[] args){
SpringApplication.run(ApplicationBegin.class, args);
}
无法从 pom.xml 中排除 tomcat 服务器,因为它编译失败。有没有办法在使用 spring boot starter web 时按照提供的方式设置 tomcat?
pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
<!-- THIS WILL BE EXCLUDE ONLY FOR WEBLOGIC DEPLOYMENT -->
<!-- <exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion> -->
</exclusions>
</dependency>
问题是应用程序在嵌入式 tomcat 下运行良好,但在 weblogic 上部署时即使没有抛出任何错误也无法正常工作。我应该去哪里看?
您可以尝试 class 最后以父项加载吗?所以 Spring 引导将使用它自己的容器库。
在尝试了我从不同人那里找到的解决方案后,它无法解决我的问题,但我现在已经解决了。我在这个主题和灵魂上看到的所有类似问题,我终于明白没有答案实际上是一个解决方案,因为在大多数情况下,问题是由于 weblogic 不理解的错误配置而发生的。最糟糕的是它甚至不会抛出错误。在我的例子中,除了 application.properties 文件和 root-context.xml,我在 /WEB-INF 位置明确指定了 web.xml 文件,并在那里定义了上下文配置位置。一旦我从上到下删除了 web.xml 和 refactored/filtered 项目依赖项,它就解决了问题。
然后我意识到,如果您的配置正确,则甚至不需要网络上针对此问题的许多方便的解决方案。例如,如果您正确使用 spring boot jpa starter,则不需要配置 jpavendor。
所以..如果你在 weblogic 上遇到过这种部署问题,你可以按照以下步骤操作 -
- 只部署应用程序的最低限度部分并使其可用
在 weblogic
- 然后添加你的关键依赖项/配置并在 weblogic 上一一部署它们并检查它是否正常工作
- 你应该总是运行你的启动应用程序首先到其他本地服务器来解决主要的配置问题..tomcat是
不错。
我遇到了同样的问题,但我终于设法解决了。
问题是 web.xml 描述符的版本。如果您将 web.xml 文件放入带有 <web-app version="2.5">
的项目中,即使您的 Weblogic 支持 servlet 3.0,spring 控制器也会抛出 404。
这也解释了您的应用程序的行为 - 为什么它在您删除 web.xml 文件后开始运行。
我已经完成了以下配置并尝试了几乎所有找到的解决方案,但没有任何帮助。当我在 war 包中部署 spring 引导应用程序时。 weblogic 日志中没有记录错误,但应用程序抛出 404 错误。
web.xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:root-context.xml</param-value>
</context-param>
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>dev</param-value>
</context-param>
<context-param>
<param-name>spring.profiles.default</param-name>
<param-value>dev</param-value>
</context-param>
<context-param>
<param-name>spring.liveBeansView.mbeanDomain</param-name>
<param-value>dev</param-value>
</context-param>
weblogic.xml
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:wls="http://www.bea.com/ns/weblogic/90"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd http://www.bea.com/ns/weblogic/90 http://www.bea.com/ns/weblogic/90/weblogic-web-app.xsd">
<wls:weblogic-version>12.1.2.0.0</wls:weblogic-version>
<wls:context-root>/services/userModule/</wls:context-root>
<wls:container-descriptor>
<wls:prefer-application-packages>
<wls:package-name>com.fasterxml</wls:package-name>
<wls:package-name>org.slf4j</wls:package-name>
<wls:package-name>org.springframework.*</wls:package-name>
</wls:prefer-application-packages>
</wls:container-descriptor>
</wls:weblogic-web-app>
application.properties
spring.profiles.default=default
spring.profiles.active=default
spring.liveBeansView.mbeanDomain=default
cms.config.monitor.dir=/server/location/application/artifacts
application.messages.file.name=application-messages
application.config.file.name=application-config
root-context.xml
它包含特定于应用程序的配置。
ApplicationBegin.java
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, JpaRepositoriesAutoConfiguration.class})
public class ApplicationBegin extends SpringBootServletInitializer implements WebApplicationInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(ApplicationBegin.class);
}
public static void main(String[] args){
SpringApplication.run(ApplicationBegin.class, args);
}
无法从 pom.xml 中排除 tomcat 服务器,因为它编译失败。有没有办法在使用 spring boot starter web 时按照提供的方式设置 tomcat? pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
<!-- THIS WILL BE EXCLUDE ONLY FOR WEBLOGIC DEPLOYMENT -->
<!-- <exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion> -->
</exclusions>
</dependency>
问题是应用程序在嵌入式 tomcat 下运行良好,但在 weblogic 上部署时即使没有抛出任何错误也无法正常工作。我应该去哪里看?
您可以尝试 class 最后以父项加载吗?所以 Spring 引导将使用它自己的容器库。
在尝试了我从不同人那里找到的解决方案后,它无法解决我的问题,但我现在已经解决了。我在这个主题和灵魂上看到的所有类似问题,我终于明白没有答案实际上是一个解决方案,因为在大多数情况下,问题是由于 weblogic 不理解的错误配置而发生的。最糟糕的是它甚至不会抛出错误。在我的例子中,除了 application.properties 文件和 root-context.xml,我在 /WEB-INF 位置明确指定了 web.xml 文件,并在那里定义了上下文配置位置。一旦我从上到下删除了 web.xml 和 refactored/filtered 项目依赖项,它就解决了问题。 然后我意识到,如果您的配置正确,则甚至不需要网络上针对此问题的许多方便的解决方案。例如,如果您正确使用 spring boot jpa starter,则不需要配置 jpavendor。 所以..如果你在 weblogic 上遇到过这种部署问题,你可以按照以下步骤操作 -
- 只部署应用程序的最低限度部分并使其可用 在 weblogic
- 然后添加你的关键依赖项/配置并在 weblogic 上一一部署它们并检查它是否正常工作
- 你应该总是运行你的启动应用程序首先到其他本地服务器来解决主要的配置问题..tomcat是 不错。
我遇到了同样的问题,但我终于设法解决了。
问题是 web.xml 描述符的版本。如果您将 web.xml 文件放入带有 <web-app version="2.5">
的项目中,即使您的 Weblogic 支持 servlet 3.0,spring 控制器也会抛出 404。
这也解释了您的应用程序的行为 - 为什么它在您删除 web.xml 文件后开始运行。