0

I am getting following error when I change my spring boot stater parent 1.5.9 RELEASE to 2.0.1 RELEASE

target/surefire-reports

    -------------------------------------------------------------------------------
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

Could it be something in my config that I need to change to make it work?

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

Application main

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

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

Entity

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

Repo

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

}

Update I just notice when I mvn clean install I also get the following errors. But I checked my build path both JRE[JavaSE-1.8] and maven dependencies are build path...

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)
Eric Huang
  • 1,114
  • 3
  • 22
  • 43
  • Everything else seems fine but spring.jpa.database-platform value should be just MYSQL instead of dialect classname. Also, do you need to specify @EnableJpaRepositories, @EntityScan? – K. Siva Prasad Reddy Apr 11 '18 at 04:26
  • you mean `org.hibernate.dialect.MySQL5InnoDBDialect` should just be `MYSQL`? I specify @EnableJpaRepositories and @EntityScan because I have seen tutorials like this so I just thought I need it.... does Spring-boot automatically take care of this? – Eric Huang Apr 11 '18 at 05:08
  • 1
    Your exception says java.lang.NoClassDefFoundError: javassist/bytecode/ClassFile. May be there is some conflict in javaassist jar.Could you clean your maven repo and run it once again? – Unknown Apr 11 '18 at 06:27
  • @Unknown Thank you.... Your suggestion made it work.... you can answer this question and I will mark as answer – Eric Huang Apr 11 '18 at 07:35

1 Answers1

1

As discussed in the comments, your error says, java.lang.NoClassDefFoundError: javassist/bytecode/ClassFile.

As you were migrating from spring boot version 1.5.9 RELEASE to 2.0.1 RELEASE, there might be some conflict in the javassist jar (3.20.0-GA vs 3.22.0-GA).

So you can clean your maven repo (delete the localRepository) and run your command once again.

Unknown
  • 2,037
  • 3
  • 30
  • 47
  • This is for people who were wondering. To clean your maven... you can `mvn dependency:purge-local-repository -DactTransitively=false -DreResolve=false` However this didn't work for me. I had to go in to my ~/.m2 and delete the repo. Here is how if any one was wondering https://stackoverflow.com/questions/24496131/where-is-my-m2-folder-on-mac-os-x-mavericks?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Eric Huang Apr 11 '18 at 08:11