Home > Back-end >  Spring boot bean @ ComponentScan scanning problem
Spring boot bean @ ComponentScan scanning problem

Time:09-25

Has always been this problem these days, Spring boot startup error, scanning is no need to register the class, today finally found that Spring boot startup classes need on the scanning of the upper directory, so you can scan to class or subclass need to register at the same level, but I found a other problem on the net, some say write directly with @ ComponentScan need scan class path, but I haven't successful test, don't know why, help to look at the trouble! Just contact spring boot first thank you,

Below is I want to scan the dao and the service, but has been an error, since the start of a see be wrong ReadingListRepository didn't scan to class, this class inherits JpaRepository



The 22:45:57 2017-04-25. 7864-349 WARN [main] ationConfigEmbeddedWebApplicationContext: Exception encountered during the context initialization - cancelling refresh attempt: org. Springframework. Beans. Factory. UnsatisfiedDependencyException: Error creating bean with the name 'readingListController: Unsatisfied dependency expressed through field' readingListRepository '; Nested exception is org. Springframework. Beans. Factory. NoSuchBeanDefinitionException: No qualifying bean of type 'org. Dawn. Oket. Dao. ReadingListRepository' available: expected at further 1 bean which qualifies as autowire candidate. The Dependency annotations: {@ org. Springframework. Beans. Factory. The annotation, Autowired (required=true)}
The 2017-04-25 22:45:57. 7864-349 the INFO [main] j.L ocalContainerEntityManagerFactoryBean: Closing the JPA EntityManagerFactory for persistence unit 'default'
The 2017-04-25 22:45:57. 7864-349 the INFO [main] org. Hibernate. Tool. Hbm2ddl. The SchemaExport: HHH000227: Running hbm2ddl schema export
The 2017-04-25 22:45:57. 7864-349 the INFO [main] org. Hibernate. Tool. Hbm2ddl. The SchemaExport: HHH000230: Schema export complete
The 22:45:57 2017-04-25. 7864-359 the INFO [main] o.a pache, catalina. Core. StandardService: Stopping the service Tomcat
The 2017-04-25 22:45:57. 7864-399 the INFO [main] utoConfigurationReportLoggingInitializer:
Error starting ApplicationContext. To display the auto - the configuration report re - run your application with 'debug' enabled.
The 2017-04-25 22:45:57. ERROR 681-7864 [main] O.S.B.D.L oggingFailureAnalysisReporter:
* * * * * * * * * * * * * * * * * * * * * * * * * * *
The APPLICATION FAILED TO START
* * * * * * * * * * * * * * * * * * * * * * * * * * *
Description:
Field readingListRepository in org. Dawn. Oket. Service. ReadingListController required a bean of type 'org. Dawn. Oket. Dao. ReadingListRepository' that could not be found.
Action:
Consider defining a bean of type 'org. Dawn. Oket. Dao. ReadingListRepository' in your configuration.
Disconnected from the target VM, address: '127.0.0.1:52934, transport:' socket '
The Process finished with exit code 1

CodePudding user response:

This annotation scanning the bag under the class, and at the same level of class package, if there are other different parent-child bag, can use basePackage assigned specific package, recommend will launch a class in the top of the bag

CodePudding user response:

The building Lord, please the problem solved? I also encountered this problem, and made several days, said online folder location, scanning type of these methods are tried, still won't do

CodePudding user response:

@ EnableJpaRepositories

CodePudding user response:

The Repository class, add annotations: @ the Repository

CodePudding user response:

Put you start the class on the top of the package

CodePudding user response:

ReadingListRepository this into ordinary Java classes, do not use interface, then add @ in the class above Service

CodePudding user response:

Don't write application in common, and write out

CodePudding user response:

Location is put in wrongly, the @ ComponentScan on @ SpringBootApplication top line

CodePudding user response:

No annotations to add annotations

CodePudding user response:

@ ComponentScan basePackages specified or not,
  • Related