将spring boot legacy webapp部署到weblogic 10.3.6服务器

时间:2015-03-30 08:55:56

标签: java deployment weblogic spring-boot weblogic-10.x

我开发了一个Spring Boot Web-App,需要将它部署到weblogic 10.3.6服务器上,所以我按照本指南创建了一个使用servlet 2.5的服务器上运行的war:http://docs.spring.io/spring-boot/docs/current/reference/html/howto-traditional-deployment.html

当我运行Application.class时,我创建的war在本地weblogic服务器和我的集成tomcat-server上工作。 它不适用于我需要将其部署到的非本地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-App工作后,至少我没有任何例外。 但是使用url my.weblogic.server:port / deployPath我得到404错误。(本地weblogic上的localhost:port / deployPath,使用我原来的web.xml,应用程序正常工作。)

我想我的本地和非本地weblogic服务器之间肯定存在差异,但我无法找到对此行为负责的人。 我试图比较weblogic服务器文件夹中的配置和jar,但我不太清楚要查找什么。我能想到的一个区别是我的本地weblogic服务器在windows上运行,而非本地weblogic服务器在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>

1 个答案:

答案 0 :(得分:2)

我找到了解决方案: 更改条目

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

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

错了。 而是添加行

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

到我的weblogic.xml解决了这个问题。

我的猜测是Spring从非本地weblogic服务器获取了错误的类加载器,而本地的不存在。

相关问题