How to set up a spring boot scan mapper file

Source: Internet
Author: User

First, scan the Mapper interface file:

1, Recommended:

In the Application.java startup file, add annotations:

@MapperScan ("Com.xxx.mapper")

2.

@Mapper
Because my mapper is a module, the portal is a module.
Mapper under the Com.xxx.mapper.
The GroupID of the portal is com.xxx so that it can be scanned @mapper directly.
But
Mybatis-generator generated mapper and not @mapper, even if the toss out, although the efficiency of the operation will not have any impact, start will be slow, wasting time, so not recommended.

Second, scan the Mapper.xml file

1, in application.properties configuration:mybatis.mapper-locations:classpath:mappers/*.xml

2.

<!--Configure the scan package to load the Mapper proxy object--
<bean class= "Org.mybatis.spring.mapper.MapperScannerConfigurer" >
<property name= "Basepackage" value= "Com.xxx.mapper" ></property>
</bean>

@SpringBootApplication
@ImportResource (locations = "Classpath:spring-dao.xml")
public class Portalapplication {

public static void Main (string[] args) {
Springapplication.run (Portalapplication.class, args);
}
}

How to set up a spring boot scan mapper file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.