gpt4 book ai didi

java - Maven 全新安装构建失败 : Spring Boot- MVC, JPA

转载 作者:行者123 更新时间:2023-11-30 07:37:21 26 4
gpt4 key购买 nike

我目前正在尝试从我的 Spring boot 项目构建一场 war 。我的项目主要是一个使用JPA持久化到DB2的MVC应用程序(这是一个项目需求)。

为了持久性,我使用从 Spring 的 CRUDRepository 类扩展的存储库接口(interface)。

我正在使用 Eclipse 进行开发,构建效果很好:我能够使用 Eclipse 启动并运行我的项目,并使用 localhost 进行测试。一切都正在自动连接并正确设置。但是,我正在尝试使用 Maven clean install 进行构建以生成 war 。

我认为问题主要在于 JPA 存储库的 Autowiring 。

我的处理方式正确吗?我应该首先使用 Maven 进行构建吗?我应该考虑一下我的 future 吗?

好的,这是我的文件:

POM.xml

https://www.dropbox.com/s/e1lb4qz1agtcac5/pom.xml?dl=0

应用程序属性:

spring.jpa.hibernate.naming-strategy: org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.database-platform= DB2Platform
#spring.jpa.database-platform: DB2Platform
spring.jpa.show-sql: true
spring.jpa.generate-ddl: true
spring.datasource.driverClassName=com.ibm.db2.jcc.DB2Driver
spring.datasource.url=jdbc:db2:localhost:50000/testing
spring.datasource.username=*A username*
spring.datasource.password=*a password*

Maven clean install console output :

[...]

2016-02-04 12:07:41.943 WARN 14116 --- [ main] o.s.w.c.s.GenericWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.sql.DataSource org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.dataSource; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceAutoConfiguration$NonEmbeddedConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: com.ibm.db2.jcc.DB2Driver

[...]

Results :

Tests in error:
APIApplicationTests.contextLoads » IllegalState Failed to load ApplicationC...

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.334 s
[INFO] Finished at: 2016-02-04T12:07:42+00:00
[INFO] Final Memory: 28M/226M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.17:test (default-test) on project API: There are test failures.
[ERROR]
[ERROR] Please refer to C:\Users\AdamM\git\api-monitor\API\target\surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

抱歉,但是控制台文件非常大,我不想在这里出现一个史诗般的问题。

最佳答案

您的项目中缺少 DB2 驱动程序依赖项,您可以在日志中看到它:

Caused by: java.lang.IllegalStateException: Cannot load driver class: com.ibm.db2.jcc.DB2Driver

您需要在某个地方获取 jar(很可能是 IBM 网站...,我怀疑它在 Maven 中心),然后将其本地安装到您的存储库中并添加到您的 pom 中。

关于java - Maven 全新安装构建失败 : Spring Boot- MVC, JPA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35201092/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com