spring boot stater parent 2.0.1 entityManagerFactory Bean创建异常

时间:2018-04-10 18:55:42

标签: spring-boot spring-data-jpa

spring boot stater parent 1.5.9 RELEASE更改为2.0.1 RELEASE

时出现以下错误

目标/万无一失的报告

    -------------------------------------------------------------------------------
Test set: com.restapispringboot.RestApiSpringbootApplicationTests
-------------------------------------------------------------------------------
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 3.158 s <<< FAILURE! - in com.restapispringboot.RestApiSpringbootApplicationTests
contextLoads(com.restapispringboot.RestApiSpringbootApplicationTests)  Time elapsed: 0.001 s  <<< ERROR!
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: javassist/bytecode/ClassFile
Caused by: java.lang.NoClassDefFoundError: javassist/bytecode/ClassFile
Caused by: java.lang.ClassNotFoundException: javassist.bytecode.ClassFile

我的配置中是否需要更改才能使其正常工作?

application.properties

spring.datasource.url=jdbc:mysql://localhost:3306/boot_rest_api
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

## Hibernate Properties
# The SQL dialect makes Hibernate generate better SQL for the chosen database
#spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect


# Hibernate ddl auto (create, create-drop, validate, update)
# spring.jpa.hibernate.ddl-auto = update
spring.jpa.hibernate.ddl-auto=create


logging.level.root=DEBUG

申请主

@SpringBootApplication
@EnableJpaRepositories("com.restapispringboot.repo")
@EntityScan("com.restapispringboot.model")
public class RestApiSpringbootApplication {

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

实体

@Entity
@Table(name = "customer")
public class Customer implements Serializable {
   // getters and setters
}

回购

public interface CustomerRepository extends CrudRepository<Customer, Long> {
    List<Customer> findByLastName(String lastName);

}

更新 我只是注意到mvn clean install时我也遇到以下错误。但我检查了我的构建路径,JRE [JavaSE-1.8]和maven依赖项都是构建路径......

ERROR] error reading /Users/erichuang/.m2/repository/org/aspectj/aspectjweaver/1.8.13/aspectjweaver-1.8.13.jar; invalid CEN header (bad signature)
[ERROR] error reading /Users/erichuang/.m2/repository/org/javassist/javassist/3.22.0-GA/javassist-3.22.0-GA.jar; invalid LOC header (bad signature)

1 个答案:

答案 0 :(得分:1)

正如评论中所述,您的错误是java.lang.NoClassDefFoundError: javassist/bytecode/ClassFile

当您从春季启动版本1.5.9 RELEASE迁移到2.0.1 RELEASE时,javassist jar (3.20.0-GA vs 3.22.0-GA)可能存在一些冲突。

所以你可以清理你的maven repo(删除localRepository)并再次运行你的命令。

相关问题