有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java将spring boot遗留webapp部署到weblogic 10.3.6服务器

我开发了一个Spring Boot Web应用程序,需要将其部署到weblogic 10.3.6服务器上,因此我按照本指南创建了一个war,它使用servlet 2.5:http://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html在服务器上工作

当我运行应用程序时,我创建的war在本地weblogic服务器和集成的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)...

试图解决这个错误,我改变了我的网站。xml:

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:*my.package.Application*</param-value>
</context-param>

在将此更改部署到非本地weblogic服务器并启动Web应用程序后,至少我没有收到任何异常。 然而,使用我的url。weblogic。服务器:端口/部署路径我得到一个404错误。(localhost:port/deployPath在我的本地weblogic上,使用我原来的web.xml,应用程序可以工作。)

我猜我的本地和非本地weblogic服务器之间一定有区别,但我找不到对这种行为负责的人。 我试图比较weblogic服务器文件夹中的配置和JAR,但我不太确定要查找什么。我能想到的一个区别是我的本地weblogic服务器运行在windows上,而非本地服务器运行在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

这些是我的(原始)文件:

网络。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>

波姆。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>

共 (1) 个答案

  1. # 1 楼答案

    我找到了解决办法: 更改条目

    <param-value>my.package.Application</param-value>
    

     <param-value>classpath:*my.package.Application*</param-value>
    

    他错了。 而是增加了一行

     <wls:package-name>org.springframework.*</wls:package-name> 
    

    我的网络逻辑。xml解决了这个问题

    我猜spring从非本地weblogic服务器上得到了错误的类加载器,而本地weblogic服务器上没有