当前位置: 首页 > 知识库问答 >
问题:

无法在tomcat 8中部署spring boot app(1.2.5)war

贾越
2023-03-14
@SpringBootApplication
public class MyApplication extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(MyApplication.class);
    }

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

http://maven.apache.org/xsd/maven-4.0.0.xsd“>4.0.0

<parent>
    <!-- Your own application should inherit from spring-boot-starter-parent -->
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.2.5.RELEASE</version>
</parent>

<groupId>com.sample.war</groupId>
<artifactId>project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>project</name>
<description>Sample Project</description>
<url>www.project.com</url>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.build.outputEncoding>UTF-8</project.build.outputEncoding>
    <main.basedir>${basedir}/../..</main.basedir>
    <m2eclipse.wtp.contextRoot>/</m2eclipse.wtp.contextRoot>

    <java-version>1.8</java-version>
    <tomcat.version>8.0.24</tomcat.version>
    <org.apache.jclouds-version>1.9.0</org.apache.jclouds-version>
    <com.mysema.querydsl-version>3.6.5</com.mysema.querydsl-version>
</properties>
<dependencies>
    <!-- Spring Boot Dependencies -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</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-data-rest</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</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>
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>
    <!-- Apache Commons -->
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.4</version>
    </dependency>
    <!-- Email -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
    </dependency>
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4.7</version>
    </dependency>
    <!-- Lombok -->
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <version>1.16.4</version>
        <scope>provided</scope>
    </dependency>
    <!-- MySQL -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <!-- HikariCP Connection Pool -->
    <dependency>
        <groupId>com.zaxxer</groupId>
        <artifactId>HikariCP</artifactId>
        <version>2.3.9</version><!--$NO-MVN-MAN-VER$ -->
    </dependency>
    <!-- QueryDSL -->
    <dependency>
        <groupId>com.mysema.querydsl</groupId>
        <artifactId>querydsl-jpa</artifactId>
        <version>${com.mysema.querydsl-version}</version>
    </dependency>
    <!-- JClouds -->
    <dependency>
        <groupId>org.apache.jclouds.driver</groupId>
        <artifactId>jclouds-slf4j</artifactId>
        <version>${org.apache.jclouds-version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.jclouds.driver</groupId>
        <artifactId>jclouds-sshj</artifactId>
        <version>${org.apache.jclouds-version}</version>
    </dependency>
    <!-- JClouds Rackspace US -->
    <dependency>
        <groupId>org.apache.jclouds.labs</groupId>
        <artifactId>rackspace-cloudfiles-us</artifactId>
        <version>${org.apache.jclouds-version}</version>
    </dependency>
    <!-- Guava -->
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>18.0</version>
    </dependency>
</dependencies>
<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
            <includes>
                <include>**/*.yaml</include>
            </includes>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>false</filtering>
            <excludes>
                <exclude>**/*.yaml</exclude>
            </excludes>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>${java-version}</source>
                <target>${java-version}</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>com.mysema.maven</groupId>
            <artifactId>apt-maven-plugin</artifactId>
            <version>1.1.3</version>
            <configuration>
                <processor>com.mysema.query.apt.jpa.JPAAnnotationProcessor</processor>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>com.mysema.querydsl</groupId>
                    <artifactId>querydsl-apt</artifactId>
                    <version>${com.mysema.querydsl-version}</version>
                </dependency>
            </dependencies>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>process</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>target/generated-sources/annotations</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

共有1个答案

微生智刚
2023-03-14

在不同的方法之后,我发现了错误,这就是我如何使用Hikari CP创建数据源的方法。如果您有类似的问题,请确保您的数据源配置如下所示:

@Bean(destroyMethod = "close")
public DataSource dataSource() {
    Properties dsProps = new Properties();
    dsProps.setProperty("url", url);
    dsProps.setProperty("user", username);
    dsProps.setProperty("password", password);

    HikariConfig hc = new HikariConfig();
    hc.setDriverClassName(driverClassName);
    hc.setJdbcUrl(url);
    hc.setMaxLifetime(maxLifetime);
    hc.setAutoCommit(autoCommit);
    hc.setConnectionTimeout(connectionTimeout);
    hc.setIdleTimeout(idleTimeout);
    hc.setMinimumIdle(minimumIdle);
    hc.setMaximumPoolSize(maximumPoolSize);
    hc.setPoolName(poolName);

    hc.setDataSourceProperties(dsProps);
    return new HikariDataSource(hc);
}

解决问题的部分是

    Properties dsProps = new Properties();
    dsProps.setProperty("url", url);
    dsProps.setProperty("user", username);
    dsProps.setProperty("password", password);

并将其包括在内

hc.setDataSourceProperties(dsProps);
 类似资料:
  • 我正在做一个maven构建在我的jenkins和创建一个战争文件,我已经配置了webphere部署插件,并成功地测试了连接。我试图部署战争文件webshere部署插件,但我得到一个错误 部署到IBM WebSphere Application Server时出错:应为Ant GLOB模式。 我猜在我部署maven build时,它需要一个ant构建。 我在jenkins中复制了WebSphereD

  • 我试图在weblogic Server12.1.3中运行Spring Boot应用程序,但遇到以下错误 BlockQuoteWebLogic.Application.ModuleException:java.lang.NoSuchMethoderRorr:org.springframework.core.Annotation.AnnotationawareOrderComparator.sort(

  • 我对Tomcat和Docker还很陌生--所以我可能在这个问题中遗漏了一个Tomcat基础知识。 我试图做的是构建一个Docker容器,该容器运行一个springboot Restful web服务,该服务只返回一些静态数据。这都是在OSX上运行的,所以我也使用了Boot2Docker。 我编写了自己的Dockerfile来构建我的应用程序运行的容器: 这个Dockerfile工作良好,并且我能够

  • 我试着在这些问题中应用所有的解决方案: 在我的web.xml中,我使用了标记'res-ref-name'。 多谢!

  • 我正在使用Java和Tomcat开发一个API项目。星期五一切都很好,但今天我不能在服务器上部署战争。下面是Tomcat中的堆栈错误: 以下是日志中的错误:

  • 我有一个工作的Jersey JAX-RS应用程序,我刚刚修改了它,以便在一个构造函数中注入一个依赖项。我试图在GlassFish上部署它,但后来我在这里遇到了这个问题。 所以我考虑在Tomcat上尝试一下,因为我认为这是HK2和CDI如何相互冲突的问题,但它在Tomcat上也不起作用,所以当我部署war文件时,我得到了这个错误: 下面是DI的实现: 我是这样注射的: 其余的代码以前工作得很好,只是