24

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,012
  • 4
  • 24
  • 33
ayaz kodiya
  • 461
  • 2
  • 5
  • 16
  • \@Configuration \@EnableAutoConfiguration \@ComponentScan are implied already due to the @SpringBootApplication annotation. – Jared Oct 20 '21 at 15:35

9 Answers9

17

I solved it by myself.

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>5.0.7.Final</version>
</dependency>
Gama11
  • 28,518
  • 9
  • 66
  • 91
ayaz kodiya
  • 461
  • 2
  • 5
  • 16
3

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

menoktaokan
  • 267
  • 3
  • 12
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
  • 5,793
  • 5
  • 23
  • 56
Shifny
  • 78
  • 4
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
  • 28,518
  • 9
  • 66
  • 91
UbuntuEGGHead
  • 83
  • 1
  • 7
1

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
  • 514
  • 4
  • 14
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 i was writing method like

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

which produced above error.

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

Ratnesh K
  • 21
  • 4
1

Remove JPA dependency if you are not using it.

    <!--   dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency -->
fatih
  • 919
  • 7
  • 24
Ali Musa
  • 9
  • 1