27

My Autoconfiguration file is not working in Spring-Boot application. I attach my configuration application file below:

@Configuration
@EnableAutoConfiguration
@ComponentScan
@SpringBootApplication
@EnableScheduling
public class Application {

  public static void main(String[] args) {
      SpringApplication springApplication=new SpringApplication(Application.class);
      System.out.println("Spring Core Version:- " + SpringVersion.getVersion());
      springApplication.run(args);

  }
}

Thrown Exception is below. How can I fix it?

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-01-19 14:50:06.085 ERROR 7614 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; 
nested exception is java.lang.NoClassDefFoundError: org/hibernate/boot/archive/scan/spi/ScanEnvironment
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1589) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:554) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBectBeanFactory.java:302) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1081) ~[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:856) ~[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542) ~[spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE]
at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) ~[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) ~[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]
at com.track.io.Application.main(Application.java:35) [classes/:na]
another
  • 3,440
  • 4
  • 27
  • 34
ayaz kodiya
  • 501
  • 2
  • 6
  • 17
  • \@Configuration \@EnableAutoConfiguration \@ComponentScan are implied already due to the @SpringBootApplication annotation. – Jared Oct 20 '21 at 15:35

11 Answers11

18

I solved it by myself.

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.0.7.Final</version>
</dependency>
Gama11
  • 31,714
  • 9
  • 78
  • 100
ayaz kodiya
  • 501
  • 2
  • 6
  • 17
4

Remove JPA dependency if you are not using it.

    <!--   dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency -->
fatih
  • 1,285
  • 11
  • 27
Ali Musa
  • 39
  • 1
3

I added @Component annotation from import org.springframework.stereotype.Component and the problem was solved.

menoktaokan
  • 346
  • 3
  • 13
2

In my case i have included jdbc api dependencies in the project so the "Hello World" not printed. After removing the below dependency it works like a charm.

       <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
Rohinibabu
  • 660
  • 10
  • 16
2

For me its due to invalid import or not availability of dependency files

check dependences and import statements

2

I came across the same:

"Error starting ApplicationContext" error

I even looked everywhere for solution nothing worked not even the above solutions, so I decided to read my errors 1 by 1 and found that there is another error at the end which is:

"No Property Found for Type" error

Then I found out that according to Spring Data JPA - Reference Documentation , Naming matters in spring, So it goes like

For repositories:
It should be named as "___Repository"

For example:

UserRepository , OrderRepository, ContactRepository

For implementations:
It should be named as "___Impl"

For example:

ContactImpl, UserServiceImpl, OrderServiceImpl

Tip 1: All repository classes/interfaces should be placed in one directory

Tip 2: All service classes/interfaces should be placed in one directory

Tip 3: If your repository is named as UserRepository, the implementation of your repository should be named as UserRepositoryImpl

Tip 4: If your service interface is named as UserService, the implementation of your service interface should be named as UserServiceImpl

For more tips read the documentation.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Shifny
  • 76
  • 5
1

It seems to me that your Hibernate libraries are not found (NoClassDefFoundError: org/hibernate/boot/archive/scan/spi/ScanEnvironment as you can see above).

Try checking to see if Hibernate core is put in as dependency:

<dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-core</artifactId>
  <version>5.0.11.Final</version>
  <scope>compile</scope>
</dependency>
Gama11
  • 31,714
  • 9
  • 78
  • 100
UbuntuEGGHead
  • 83
  • 1
  • 7
1

Sometimes in spring boot it happens when you use the same port twice. Make sure you have stopped the application running somewhere else or stop the opening port.

  • 2
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 06 '21 at 20:17
1

I came across the same error

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2021-12-21 22:57:45.237 ERROR 4952 --- [ main] o.s.boot.SpringApplication : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository' defined in com.sts.dao.UserRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.EnableJpaRepositoriesConfiguration: No property findbyName found for type User!

Because I defined wrong name for Custom Methods( or Derived methods) in My Repository while using Spring Data JPA, then I search Spring data Jpa reference where I found that there is strict naming convention for Custom methods which we need to follow otherwise it gives errors.

like findByName(), findInAge() , findByAgeLessThan()

In my case, was writing methods like

**public List<User> findbyName(String name);**

which produced the above error.

Suggestion: While working with spring data, JPA strictly follow camelCase and all naming conventions defined in the reference doc to avoid errors.

Additionally...

You can also run into such errors when you try to modify a custom query using any of the JPQL implementations without specifying the @Modifying tag and/or the @Transactional tag. Especially when the modified JPQL method has its Transactional state set to ReadOnly=true

Say, for instance, you're implementing a custom query in one of your Repositories.

@Query("DELETE FROM STUDENT s WHERE s.id = ?1")
int deleteStudentById(Long id);

Because the JPA repository always maps a query result to an entity, the above code will result in an error, because your query is not returning an Entity.

So to make it work, you will need to explicitly specify the @Modifying tag and also the @Transactional tag in this case for your query to run successfully.

@Transactional
@Modifying
@Query("DELETE FROM STUDENT s WHERE s.id = ?1")
int deleteStudentById(Long id);

[Spring doc https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#transactions][1]

Austin
  • 1
  • 4
Ratnesh K
  • 19
  • 6
0

I had the same error. My fix was to add "@Component" to the top of my class declaration. In your case it would be:

@Component
public class Application {

  public static void main(String[] args) {
      SpringApplication springApplication=new SpringApplication(Application.class);
      System.out.println("Spring Core Version:- " + SpringVersion.getVersion());
      springApplication.run(args);

  }
}
Kem Andrew
  • 26
  • 4
0

with Spring boot version 3.0.3 : I solved it by removing JPA dependency Starter ( i dont need it completly) and I replaced it by spring-data-commons and spring-data-jpa

   <!-- <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
        <version>3.0.3</version>
    </dependency>                   -->

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-commons</artifactId>
        <version>3.0.2</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>3.0.2</version>
    </dependency>
user2898676
  • 19
  • 1
  • 4