简体   繁体   中英

Maven Clean Install build fails: Spring Boot- MVC, JPA

I'm currently attempting to build a war from my Spring boot project. My project is mainly an MVC application that uses JPA to persist to DB2(It was a project requirement).

For persistence, I'm using repo interfaces extended from Spring's CRUDRepository class.

I'm using Eclipse for development, and the build is fine: I'm able to get my project up and running with Eclipse, test with localhost. Everything is being autowired and set up correctly. However, I'm attempting to build with maven clean install to generate a war.

I think the problem is mainly with the autowiring of the JPA repos.

Am I going about this the right way? Should I be building with maven in the first place? Should I contemplate my future?

Okay, here is my files:

POM.xml

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

Application.properties:

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*

The 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

Sorry, but the console file is quite large and I didn't want an epic saga of a question here.

You are missing DB2 driver dependency in your project, you can see it in your log:

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

You need to get the jar somewhere (most likely IBM website ..., I doubt it is in the maven central), then install it locally into your repository and add to your pom.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM