如何在Weblogic 12C上运行Spring Boot应用程序? [英] How to Spring Boot app run on weblogic 12C?

查看:97
本文介绍了如何在Weblogic 12C上运行Spring Boot应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在weblogic 12c上运行Spring Boot应用程序.

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);
    }
}

现在,我将应用程序部署在weblogic上.

Now, I deploy app on weblogic.

它显示部署成功.

但是,控制台中没有Spring Boot日志消息.

However, there are no Spring Boot log messages in the console.

我的控制器配置有映射 @RequestMapping("/home/sign_in").

My controller is configured with a mapping @RequestMapping("/home/sign_in").

当我访问 http://localhost:7001/demo/home/sign_in 时,我得到了 404 .

When i visit http://localhost:7001/demo/home/sign_in, I got 404.

控制台没有任何更改.

我想在Weblogic上运行Spring Boot应用程序怎么办?

I want to run Spring Boot applications on Weblogic how to do?

我需要帮助.非常感谢.

I need help. Thank you very much.

PS:

这是我的 pom.xml 文件的一部分:

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>

推荐答案

在Web_INF中添加Weblogic.xml和dispatcher-servlet [空].同样对于数据源配置,在weblogic中定义它并在此处使用JNDI名称[请参见下文]

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]

在application.properties中spring.datasource.jndi-name = xyz-jndi-name

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>

这篇关于如何在Weblogic 12C上运行Spring Boot应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆