SPRINGBOOT项目部署WEBLOGIC
一、修改pom.xml
1.打包方式改为war
<packaging>war</packaging>
2.依赖主要增加如下内容
打包时增加一个tomcat的provided依赖,本地启动时需要注释掉,否则会报
classnotfoundexception javax.servlet.filter
1.test范围是指测试范围有效,在编译和打包时都不会使用这个依赖
2.compile范围是指编译范围内有效,在编译和打包时都会将依赖存储进去
3.provided依赖,在编译和测试过程中有效,最后生成的war包时不会加入 例如:
servlet-api,因为servlet-api tomcat服务器已经存在了,如果再打包会冲突
4.runtime在运行时候依赖,在编译时候不依赖
默认依赖范围是compile
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.1.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-legacy</artifactId> <version>2.1.0.RELEASE</version> </dependency> <!-- 本地启动时需要注释掉下面的依赖 --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency>
3.build修改如下
<build> <finalName>xxxxxClient</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <configuration> <attachClasses>true</attachClasses> <failOnMissingWebXml>false</failOnMissingWebXml> <archive> <manifestEntries> <Weblogic-Application-Version>${project.version}</Weblogic-Application-Version> </manifestEntries> <manifest> <addClasspath>true</addClasspath> <addClasspath>lib/</addClasspath> </manifest> </archive> <webResources> <resource> <directory>${project.basedir}/lib</directory> <targetPath>WEB-INF/lib</targetPath> <filtering>false</filtering> </resource> </webResources> <warName>${project.artifactId}</warName> </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <version>${spring.boot.version}</version> <configuration> <fork>true</fork> <includeSystemScope>true</includeSystemScope> <!-- <classifier>BOOT</classifier>--> </configuration> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> </plugins> </build>
二、修改启动类
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.web.WebApplicationInitializer; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController @SpringBootApplication public class DemoApplication extends SpringBootServletInitializer implements WebApplicationInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(DemoApplication.class); } public static void main(String[] args) { SpringApplication.run(DemoApplication.class); } }
三、增加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>com.yaya.SpringBootWebLogicApplication</param-value> </context-param> <listener> <listener-class>org.springframework.boot.legacy.context.web.SpringBootContextLoaderListener</listener-class> <!-- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>--> </listener> <!--找不到metricFilter的bean,可注释掉下面内容--> <!--<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://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd"> <wls:context-root>/demo</wls:context-root> <!-- <wls:context-root>/</wls:context-root> --> <wls:fast-swap> <wls:enabled>true</wls:enabled> </wls:fast-swap> <wls:container-descriptor> <wls:prefer-application-packages> <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>
最后打包,生产demo.war,部署到weblogic即可