Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of springBoot mybatis packet scanning

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of how to solve the springBoot mybatis package scanning problem, the content is detailed and easy to understand, the operation is simple and fast, and it has a certain reference value. I believe you will gain something after reading this springBoot mybatis package scanning problem. Let's take a look at it.

SpringBoot mybatis packet scan @ MapperScan (basePackages = {"com.zscat.*.dao", "com.zscat.*.*.dao"}) @ EnableTransactionManagement (proxyTargetClass = true) @ SpringBootApplication@MapperScan (basePackages = {"com.zscat.*.dao", "com.zscat.*.*.dao"}) public class ShopServiceApplication {public static void main (String [] args) {SpringApplication application = new SpringApplication (ShopServiceApplication.class); application.run (args);}} springBoot cannot scan mybatis interface package

You only need to annotate the spring boot startup class and specify the interface file package path in the jar package.

@ MapperScan (basePackages = "com.xx.**.dao")

If you use @ Controller and @ EnableAutoConfiguration annotations, you should add another annotation: @ ComponentScan.

@ Controller and @ EnableAutoConfiguration do not have the ability to scan annotations, while @ ComponentScan is

Springboot is specially used to scan @ Component, @ Service, @ Repository, @ Controller and other annotations

Summary:

There are two annotated configuration methods for springboot startup class configuration scanning:

1. @ Controller

@ EnableAutoConfiguration @ ComponentScan

2. @ SpringBootApplication

The @ SpringBootApplication annotation is equivalent to @ Configuration, @ EnableAutoConfiguration and @ ComponentScan

In addition, application.java (startup class) should also be placed in the root directory according to official recommendations, so that Service and dao can be scanned, otherwise it will cause problems that can not be scanned.

-Update at: 2018-10-14--

Recently, a new scan annotation has been added to the latest version of springboot 2.0.5.RELEASE, and the new version of springboot application can be placed anywhere, as long as you add

@ ComponentScan (basePackages = {"com.oskyhang", "com.frames"})

Annotations can be done, annotations specify the scanned package, it can be scanned, which is more flexible and convenient.

This is the end of the article on "how to solve the problem of springBoot mybatis packet scanning". Thank you for reading! I believe that everyone has a certain understanding of the knowledge of "how to solve the springBoot mybatis packet scanning problem". If you want to learn more knowledge, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report