当我使用SpringBoot时,为什么在Weblogic上部署Web应用程序时需要使用web.xml?

时间:2020-02-10 08:44:34

标签: spring-boot weblogic12c

我制作了基于SpringBoot 2.x的Web应用程序。我正在使用Intellij Idea 2019,并且在那里配置了在weblogic 12.x上部署Web应用程序。


<dependencies>


        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>

             <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>

        <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-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

我制作了* .xml

src / main / webapp / WEB-INF / dispatcherServlet-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd">

</beans>

src / main / webapp / WEB-INF / 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>12.2.1</wls:weblogic-version>
    <wls:context-root>web</wls:context-root>
    <wls:container-descriptor>
        <wls:prefer-application-packages>
            <wls:package-name>org.slf4j.*</wls:package-name>
            <wls:package-name>org.springframework.*</wls:package-name>
            <wls:package-name>javax.persistence.*</wls:package-name>
        </wls:prefer-application-packages>
    </wls:container-descriptor>
</wls:weblogic-web-app>

然后我上课...

WebLogicApplication.class

@SpringBootApplication
public class WebLogicApplication {

    public static void main(String[] args) {
        SpringApplication.run(WebLogicApplication.class, args);
    }

}

ServletInitializer.class

public class ServletInitializer extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(WebLogicApplication.class);
    }

}

静态内容。

静态/ 索引 .html

我将Intellij设置为在WebLogic服务器上运行Web应用程序。

但是我遇到了错误者...

一个错误


<The log file C:\oracle_home_develop\user_projects\domains\base_domain\servers\AdminServer\logs\AdminServer.log will be rotated. Reopen the log file if tailing has stopped. This can happen on some platforms, such as Windows.>  <10.02.2020 11:35:44,322 MSK> <Error> <Default> <BEA-000000> <Got an exception while rotating log file. java.lang.RuntimeException: com.bea.logging.LogRotationException: Error rotating log file C:\oracle_home_develop\user_projects\domains\base_domain\servers\AdminServer\logs\AdminServer.log  at com.bea.logging.LogFileRotator$1.run(LogFileRotator.java:254)    at com.bea.logging.LogFileRotator.executeGlobalAccountRunnerTask(LogFileRotator.java:243)   at com.bea.logging.LogFileRotator.rotate(LogFileRotator.java:248)

第二次错误

[2020-02-10 11:35:58,625]神器weblogic:战争爆炸:神器正在部署中,请稍候... <10.02.2020 11:35:58,915 MSK> <[WebAppModule(weblogic_war_exploded:weblogic-0.0.1-SNAPSHOT)]在Web应用程序“ E:!_ Install \ git_hub_projects \ weblogic \ target \ weblogic-0.0.1-中解析描述符错误快照” weblogic.application.descriptor.MissingRootElementException:[Munger:2156204]描述符文件E:!_ Install \ git_hub_projects \ weblogic \ target \ weblogic-0.0.1-SNAPSHOT / WEB-INF / web中缺少根元素web-app。 xml。 在weblogic.application.descriptor.BasicMunger2._onStartElement(BasicMunger2.java:506) 在weblogic.application.descriptor.BasicMunger2.next(BasicMunger2.java:441) 在weblogic.application.descriptor.VersionMunger._next(VersionMunger.java:346) 在weblogic.application.descriptor.VersionMunger.next(VersionMunger.java:231) 在weblogic.application.descriptor.VersionMunger.consumeInputStream(VersionMunger.java:599) 被截断了。请参阅日志文件以获取完整的stacktrace

<10.02.2020 11:35:58,920 MSK>

Update-1

我固定了。

<?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://xmlns.oracle.com/weblogic/weblogic-web-app
                      http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">

    <wls:weblogic-version>12.2.1</wls:weblogic-version>
    <wls:context-root>web</wls:context-root>
    <wls:container-descriptor>
        <wls:prefer-application-packages>
            <wls:package-name>org.slf4j.*</wls:package-name>
            <wls:package-name>org.springframework.*</wls:package-name>
            <wls:package-name>javax.persistence.*</wls:package-name>
        </wls:prefer-application-packages>
    </wls:container-descriptor>
</wls:weblogic-web-app>

我删除了src / main / webapp / WEB-INF / dispatcherServlet-servlet .xml

我检查了* .war-没有生成web.xml

但是,我再次遇到错误

[Munger:2156204]描述符文件E:_Install \ git_hub_projects \ weblogic \ target \ weblogic-0.0.1-SNAPSHOT / WEB-INF / web.xml中缺少根元素web-app。

Update_3

我更改了入口点...

@SpringBootApplication
public class WebLogicApplication extends SpringBootServletInitializer implements WebApplicationInitializer {

    public static void main(String[] args) {
        SpringApplication.run(WebLogicApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(WebLogicApplication.class);
    }
}

然后

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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
         https://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>2.2.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <groupId>com.weblogic</groupId>
    <artifactId>weblogic</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>weblogic</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>

        <version.apache.maven.plugins>3.8.1</version.apache.maven.plugins>
        <version.mapstruct>1.3.0.Final</version.mapstruct>

        <version.apache.common.lang3>3.9</version.apache.common.lang3>
        <version.apache.commons.text>1.8</version.apache.commons.text>
        <version.apache.commons.beanutils>1.9.4</version.apache.commons.beanutils>
        <version.datasource.proxy>1.6</version.datasource.proxy>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
        </dependency>

             <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>

         <!--исключаем из компиляции встроенный Tomcat-->
        <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-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

com.weblogic.weblogic.controller。 HomeController


@Controller
public class HomeController {


    private String message = "Hello World";

    @GetMapping("/")
    public String getIndex() {

        return "index";
    }
}

我再次组装了该项目,但是我在Weblogic上进行了直接部署(不使用Intellij Idea),并且再次发现错误

[http://172.17.89.177:7001/web]

错误500-内部服务器错误

java.lang.NullPointerException 在weblogic.servlet.internal.ServletResponseImpl.sendContentError(ServletResponseImpl.java:738) 在weblogic.servlet.internal.ServletResponseImpl.sendError(ServletResponseImpl.java:796) 在weblogic.servlet.internal.ServletResponseImpl.sendError(ServletResponseImpl.java:713) 在org.springframework.boot.web.servlet.support.ErrorPageFilter $ ErrorWrapperResponse.sendErrorIfNecessary(ErrorPageFilter.java:349) 在org.springframework.boot.web.servlet.support.ErrorPageFilter $ ErrorWrapperResponse.getWriter(ErrorPageFilter.java:363) 在org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration $ StaticView.render(ErrorMvcAutoConfiguration.java:227) 在org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1373) 在org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1118) 在org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1057) 在org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) 在org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) 在org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:687) 在org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:790) 在weblogic.servlet.internal.StubSecurityHelper $ ServletServiceAction.run(StubSecurityHelper.java:295) 在weblogic.servlet.internal.StubSecurityHelper $ ServletServiceAction.run(StubSecurityHelper.java:260) 在weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:137) ...

Update_4

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://xmlns.oracle.com/weblogic/weblogic-web-app
                      http://xmlns.oracle.com/weblogic/weblogic-web-app/1.9/weblogic-web-app.xsd">

    <wls:weblogic-version>12.2.1.4.0</wls:weblogic-version>
    <wls:context-root>/api</wls:context-root>
    <wls:container-descriptor>
        <wls:prefer-application-packages>
            <wls:package-name>org.slf4j.*</wls:package-name>
            <wls:package-name>org.springframework.*</wls:package-name>
            <wls:package-name>javax.persistence.*</wls:package-name>
        </wls:prefer-application-packages>
    </wls:container-descriptor>
</wls:weblogic-web-app>

我还创建了 src / main / webapp / WEB-INF / web.xml 。它是空的。

src / main / webapp / index.html ,只有它在这里。

运行/调试配置

URL:http://localhost:7001/api

以及所有其他一切

现在正在工作。

我认为...它需要创建Java配置。这里将描述访问静态内容的规则...

我已经看到许多示例,其中/ resources中包含静态内容。 我现在该如何设计? 如何捆绑使用:Spring Bolt 2.x + HTML + Weblogic? 如何限制对静态内容的访问?

谁知道如何解决此问题?

更新

我在以下位置创建了静态内容(* .html,*。css):

  • src / main / resources / templates
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Hello Weblogic!</title>
    <link type="text/css" th:href="@{/css/style.css}" rel="stylesheet"/>
</head>
<body>
<div class="st">
    Hello Weblogic!!!!!!!!!!!!!!!
</div>

</body>
</html>
  • src / main / resources / static / css / style.css

  • 控制器

@Controller
public class IndexController {

    @RequestMapping(value="/", method= RequestMethod.GET)
    public String index() {
        return "index";
    }
}
  • pom.xml
  <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
  • src / main / webapp / WEB-INF / web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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"
         version="3.1">

</web-app>
  • src / main / webapp / WEB-INF / 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
        https://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd
        http://xmlns.oracle.com/weblogic/weblogic-web-app
        https://xmlns.oracle.com/weblogic/weblogic-web-app/1.9/weblogic-web-app.xsd">

    <wls:context-root>sat</wls:context-root>
    <wls:container-descriptor>
        <wls:prefer-application-packages>
            <wls:package-name>org.slf4j</wls:package-name>
        </wls:prefer-application-packages>
    </wls:container-descriptor>
</wls:weblogic-web-app>

有效。

0 个答案:

没有答案