问题
How to Spring Boot app run on weblogic 12c.
My application class like this :
package com.website;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.sql.DataSource;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
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.context.properties.ConfigurationProperties;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.web.WebApplicationInitializer;
@EnableAutoConfiguration
@ComponentScan
@MapperScan("com.website.mapper")
@SpringBootApplication
public class Application extends SpringBootServletInitializer implements WebApplicationInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(Application.class);
}
@Bean
@ConfigurationProperties(prefix = "spring.datasource")
public DataSource dataSource() {
return new org.apache.tomcat.jdbc.pool.DataSource();
}
@Bean
public SqlSessionFactory sqlSessionFactoryBean() throws Exception {
SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
sessionFactoryBean.setDataSource(dataSource());
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
sessionFactoryBean.setMapperLocations(resolver.getResources("classpath:/mybatis/*.xml"));
return sessionFactoryBean.getObject();
}
/**
* Start
*
* @Created by zyj on 2016年11月28日
* @param args
* @Version 1.0
*/
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Now, I deploy app on weblogic.
It shows the deployment success.
However, there are no Spring Boot log messages in the console.
My controller is configured with a mapping @RequestMapping("/home/sign_in")
.
When i visit http://localhost:7001/demo/home/sign_in
, I got 404
.
Console without any changes.
I want to run Spring Boot applications on Weblogic how to do?
I need help. Thank you very much.
PS :
This is part of my pom.xml
file :
<modelVersion>4.0.0</modelVersion>
<groupId>com.smember</groupId>
<artifactId>website</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>website Maven Webapp</name>
<url>http://maven.apache.org</url>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.2.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
...
</dependencies>
...
<build>
<finalName>website</finalName>
</build>
回答1:
Add Weblogic.xml and dispatcher-servlet [empty] in Web_INF. Also for datasource configuration, define it in weblogic and use the JNDI name here [see below]
In application.properties spring.datasource.jndi-name=xyz-jndi-name
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.1.1</wls:weblogic-version>
<wls:context-root>bh</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>
回答2:
Weblogic expects WAR package. You should change your packaging to WAR instead of JAR by modifying your pom.xml.
来源:https://stackoverflow.com/questions/41441218/how-to-spring-boot-app-run-on-weblogic-12c