spring boot 、spring cloud 部署到weblogic

客户提出奇葩要求,要把spring cloud部署到weblogic中,研究成功后结果因为服务器jdk只能用1.6所以没能部署到生产环境使用,又用spring mvc重写了代码。

1、修改应用主类 Application

package com.bake.urpt.micro;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.WebApplicationInitializer;

@EnableAutoConfiguration
@Configuration
@ComponentScan
public class ModelConfigApplication extends SpringBootServletInitializer implements WebApplicationInitializer {
	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
		return application.sources(ModelConfigApplication.class);
	}
	public static void main(String[] args) {
		SpringApplication.run(ModelConfigApplication.class, args);
	}
}

2、在项目根目录下添加文件夹WEB-INF,并添加web.xml 和weblogic.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>com.bake.urpt.micro.ModelConfigApplication</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://xmlns.oracle.com/weblogic/weblogic-web-app
        http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">
    <!-- 项目名称,引用jar包 -->
    <wls:context-root>/modelconfig-service</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:prefer-application-packages>
    </wls:container-descriptor>
</wls:weblogic-web-app>

3、pom.xml修改,去掉tomcat引用:

<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <packaging>war</packaging>
  <parent>
    <groupId>com.bake.urpt.serv</groupId>
    <artifactId>urpt-proj</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <groupId>com.bake.urpt.serv.modelconfig</groupId>
  <artifactId>modelconfig-service</artifactId>
  <name>modelconfig-service</name>
  <description>数据模型配置服务</description>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>
  	<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-legacy</artifactId>
        <version>1.0.2.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>test</scope>
    </dependency>
	<dependency>
     	<groupId>com.bake.urpt.serv.common</groupId>
    	<artifactId>common-module</artifactId>
    	<version>0.0.1-SNAPSHOT</version>
	</dependency> 
	<!-- jdbc -->
	<dependency>
    	<groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
	</dependency>	
	
	<!-- 
	<dependency>  
	   <groupId>com.oracle</groupId>  
	   <artifactId>ojdbc6</artifactId>  
	   <version>11.2.0.3</version>  
	</dependency>  
	 -->	
  </dependencies>
  <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                	<version>2.5</version>
                    <attachClasses>true</attachClasses>
                    <archive>
                        <manifestEntries>
                            <Weblogic-Application-Version>1.0</Weblogic-Application-Version>
                        </manifestEntries>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <addClasspath>lib/</addClasspath>
                        </manifest>
                    </archive>
                    <webResources>
                        <resource>
                            <directory>WEB-INF</directory>
                        </resource>
                    </webResources>
                    <webXml>WEB-INF\web.xml</webXml>
                    <warName>modelconfig-service</warName>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <!-- <version>1.4.6</version> -->
                <configuration>
                    <classifier>BOOT</classifier>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

然后编译打包部署即可。

发表评论

电子邮件地址不会被公开。 必填项已用*标注