用oracle作为数据库打包spring boot应用程序

时间:2018-06-07 06:40:09

标签: java spring-boot intellij-idea

我正在尝试打包我的spring启动应用程序,以便我可以在tomcat服务器上部署它。在观看youtube视频后,我扩展了SpringBootServletInitializer类并进行了一些更改。

 @ComponentScan("com.infodev.loksewa")
    @SpringBootApplication
    public class LoksewaApplication extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(LoksewaApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(LoksewaApplication.class);
    }
}

pox.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.infodev</groupId>
    <artifactId>loksewa</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>loksewa</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.2.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <finalName>psclockunlock</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>

pom.xml无法自动导入ojdbc jar文件,所以我手动添加了jar文件: -

enter image description here

当我在我的IDE(Intellij Idea)上运行应用程序时,它成功运行。但现在我需要将其打包为war文件并将其部署在我的tomcat服务器上。所以当我从intellij打包时,我得到一个错误,表示无法加载驱动程序。

Caused by: java.lang.IllegalStateException: 
Cannot load driver class: oracle.jdbc.driver.OracleDriver

在打包应用程序时,我应该在哪里放置这个ojdbc jar文件?

1 个答案:

答案 0 :(得分:4)

由于Oracle许可证限制,Oracle JDBC驱动程序在公共Maven存储库中不可用。要将Oracle JDBC驱动程序与Maven一起使用,您必须手动将其下载并安装到Maven本地存储库中。要安装Oracle jdbc驱动程序,请发出以下命令:

  

mvn install:install-file -Dfile = {Path / to / your / ojdbc.jar}   -DgroupId = com.oracle   -DartifactId = ojdbc6 -Dversion = 11.2.0 -Dpackaging = jar

添加ojdbc6依赖

<dependency>
    <groupId>com.oracle</groupId>
    <artifactId>ojdbc6</artifactId>
    <version>11.2.0</version>
</dependency>