springboot 项目在tomcat里部署正常,可是部署到weblogic里,能访问jsp,但是不加载ApplicationListener实现类……
1.首先在WEB-INF下添加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>
<!--配置spring boot main方法的入口类全路径 -->
<param-value>com.mofit.account.divide.NontaxAccountDivideApplication</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>
2.在WEB-INF下新建weblogic.xml,代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="http://www.bea.com/ns/weblogic/90"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!-- <jsp-descriptor>
<keepgenerated>false</keepgenerated>
<page-check-seconds>-1</page-check-seconds>
<verbose>true</verbose>
<debug>true</debug>
</jsp-descriptor> -->
<container-descriptor>
<prefer-web-inf-classes>true</prefer-web-inf-classes>
</container-descriptor>
<context-root>share</context-root>
</weblogic-web-app>
如果不创建weblogic.xml,部署到weblogic上会找不到war包所依赖的lib,上面的xml告诉weblogic优先使用war包里的WEB-INF\lib里的jar。创建weblogic.xml要注意xml里的dtd声明,不同的weblogic版本,内容不一样。否则报验证xml错误。如problem: cvc-complex-type.2.3: Element 'container-descriptor@http://xmlns.oracle.com/weblogic/weblogic-web-app' with element-only content type cannot have text content.:<null>
3.在pom.xml里添加weblogic启动时的依赖包,如下:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-legacy</artifactId>
<version>1.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
4.我的项目使用的jdk1.7编译,weblogic10.3.1默认使用的jdk为1.6,需要修改weblogic的jdk,否则报class版本异常。需要修改2个文件,分别是C:\Oracle\Middleware\wlserver_10.3\common\bin\commEnv.cmd,和C:\Oracle\Middleware\user_projects\domains\base_domain\bin\setDomainEnv.cmd。其中commEnv.cmd,修改地方如下图:
setDomainEnv.cmd修改的地方如下图:
该文件一共修改2个地方 。
5.修改完后,重新clean,build,使用eclipse导出war包,部署到weblogic即可看到ApplicationListener实现类里的info日志,部署成功。
6.大家在部署的时候如果遇到什么问题,欢迎随时留言讨论。