将 spring 启动遗留 Web 应用程序部署到 WebLogic 10.3.6 服务器
Deploying a spring boot legacy webapp to a weblogic 10.3.6 server
我开发了一个 Spring Boot Web-App 并需要将其部署到 weblogic 10.3.6 服务器,所以我按照本指南创建了一个 war 在带有 servlet 2.5 的服务器上工作: http://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html.
我创建的 war 在本地 weblogic 服务器上工作,当我 运行 Application.class 时在我的集成 tomcat 服务器上工作。
它不适用于我需要将其部署到的非本地 weblogic 服务器。
当我尝试启动它时出现以下异常:
... Caused By: java.io.FileNotFoundException: Could not open ServletContext resource [/my.package.Application]
at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:117)...
为了解决这个错误,我更改了 web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:*my.package.Application*</param-value>
</context-param>
此更改部署到非本地 weblogic 服务器并启动 Web 应用程序后,至少我没有收到任何异常。
但是使用 url my.weblogic.server:port/deployPath 我得到一个 404 错误。(本地主机:port/deployPath 在我的本地 weblogic 上,使用我原来的 web.xml,应用程序工作.)
我想我的本地和非本地 weblogic 服务器之间一定有区别,但我找不到对这种行为负责的人。
我试图比较 weblogic 服务器文件夹中的配置和 jars,但我不太确定要查找什么。我能想到的一个区别是 windows 上的本地 weblogic 服务器 运行s 和 linux.
上的非本地服务器
我将不胜感激任何有关查找内容的帮助和提示。
我的项目结构:
src
|main
|java
|demo
|resources
|static
|resources
|css
|... my css files
|js
|... my js files
|templates
|my .html (thymeleafe) files
application.properties
|test
|...
|webapp
|WEB-INF
|web.xml
|weblogic.xml
pom.xml
这些是我的(原始)文件:
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>my.package.Application</param-value>
</context-param>
<listener>
<listener-class>org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>metricFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>metricFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextAttribute</param-name>
<param-value>org.springframework.web.context.WebApplicationContext.ROOT</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
weblogic.xml :
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
<wls:weblogic-version>10.3.6</wls:weblogic-version>
<wls:context-root>/deployPath</wls:context-root>
<wls:container-descriptor>
<wls:prefer-application-packages>
<wls:package-name>org.slf4j.*</wls:package-name>
<wls:package-name>javax.persistence.*</wls:package-name>
</wls:prefer-application-packages>
</wls:container-descriptor>
</wls:weblogic-web-app>
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.8.RELEASE</version>
</parent>
<groupId>my.groupid</groupId>
<artifactId>myArtifactId</artifactId>
<packaging>${packaging.type}</packaging>
<properties>
<main.basedir>${basedir}/../..</main.basedir>
<packaging.type>war</packaging.type>
<deploy.path>/deployPath</deploy.path>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-legacy</artifactId>
<version>1.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>14</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
<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-log4j</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring4</artifactId>
</dependency>
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>
....
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
<webResources>
<resource>
<directory>${project.basedir}/src/main/resources/static
</directory>
</resource>
<resource>
<directory>${project.basedir}/src/webapp
</directory>
</resource>
</webResources>
<warName>myName</warName>
</configuration>
</plugin>
</plugins>
</build>
</project>
我找到了解决方案:
更改条目
<param-value>my.package.Application</param-value>
到
<param-value>classpath:*my.package.Application*</param-value>
错了。
而是添加 Line
<wls:package-name>org.springframework.*</wls:package-name>
我的 weblogic.xml 解决了这个问题。
我的猜测是 spring 从非本地 weblogic 服务器获取了错误的类加载器,本地服务器上不存在该类加载器。
我开发了一个 Spring Boot Web-App 并需要将其部署到 weblogic 10.3.6 服务器,所以我按照本指南创建了一个 war 在带有 servlet 2.5 的服务器上工作: http://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html.
我创建的 war 在本地 weblogic 服务器上工作,当我 运行 Application.class 时在我的集成 tomcat 服务器上工作。 它不适用于我需要将其部署到的非本地 weblogic 服务器。
当我尝试启动它时出现以下异常:
... Caused By: java.io.FileNotFoundException: Could not open ServletContext resource [/my.package.Application]
at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:117)...
为了解决这个错误,我更改了 web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:*my.package.Application*</param-value>
</context-param>
此更改部署到非本地 weblogic 服务器并启动 Web 应用程序后,至少我没有收到任何异常。 但是使用 url my.weblogic.server:port/deployPath 我得到一个 404 错误。(本地主机:port/deployPath 在我的本地 weblogic 上,使用我原来的 web.xml,应用程序工作.)
我想我的本地和非本地 weblogic 服务器之间一定有区别,但我找不到对这种行为负责的人。 我试图比较 weblogic 服务器文件夹中的配置和 jars,但我不太确定要查找什么。我能想到的一个区别是 windows 上的本地 weblogic 服务器 运行s 和 linux.
上的非本地服务器我将不胜感激任何有关查找内容的帮助和提示。
我的项目结构:
src
|main
|java
|demo
|resources
|static
|resources
|css
|... my css files
|js
|... my js files
|templates
|my .html (thymeleafe) files
application.properties
|test
|...
|webapp
|WEB-INF
|web.xml
|weblogic.xml
pom.xml
这些是我的(原始)文件:
web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>my.package.Application</param-value>
</context-param>
<listener>
<listener-class>org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>metricFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>metricFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextAttribute</param-name>
<param-value>org.springframework.web.context.WebApplicationContext.ROOT</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
weblogic.xml :
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
<wls:weblogic-version>10.3.6</wls:weblogic-version>
<wls:context-root>/deployPath</wls:context-root>
<wls:container-descriptor>
<wls:prefer-application-packages>
<wls:package-name>org.slf4j.*</wls:package-name>
<wls:package-name>javax.persistence.*</wls:package-name>
</wls:prefer-application-packages>
</wls:container-descriptor>
</wls:weblogic-web-app>
pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.8.RELEASE</version>
</parent>
<groupId>my.groupid</groupId>
<artifactId>myArtifactId</artifactId>
<packaging>${packaging.type}</packaging>
<properties>
<main.basedir>${basedir}/../..</main.basedir>
<packaging.type>war</packaging.type>
<deploy.path>/deployPath</deploy.path>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-legacy</artifactId>
<version>1.0.1.RELEASE</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>14</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
<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-log4j</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring4</artifactId>
</dependency>
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>
....
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
</archive>
<webResources>
<resource>
<directory>${project.basedir}/src/main/resources/static
</directory>
</resource>
<resource>
<directory>${project.basedir}/src/webapp
</directory>
</resource>
</webResources>
<warName>myName</warName>
</configuration>
</plugin>
</plugins>
</build>
</project>
我找到了解决方案: 更改条目
<param-value>my.package.Application</param-value>
到
<param-value>classpath:*my.package.Application*</param-value>
错了。 而是添加 Line
<wls:package-name>org.springframework.*</wls:package-name>
我的 weblogic.xml 解决了这个问题。
我的猜测是 spring 从非本地 weblogic 服务器获取了错误的类加载器,本地服务器上不存在该类加载器。