spring boot 2.3 jpa querydsl 调整 dsl 的包路径

添加插件 生成 Q…实体


            
                com.mysema.maven
                apt-maven-plugin
                1.1.3
                
                    
                        com.querydsl
                        querydsl-apt
                        ${querydsl.version}
                    
                
                
                    
                        
                            process
                        
                        
                            target/generated-sources/java
                            com.querydsl.apt.jpa.JPAAnnotationProcessor
                            
                            	
                                .dsl
                            
                        
                    
                
            

在插件中我们配置了 querydsl.packageSuffix 所以 生成的包路径如下
spring boot 2.3 jpa querydsl 调整 dsl 的包路径_第1张图片

此时重启项目 会报错 提示找不到 cn.zhangfusheng.user.model.QTbUser ,这是因为我们配置了 dsl 的包前缀

解决办法

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.querydsl.EntityPathResolver;
import org.springframework.data.querydsl.SimpleEntityPathResolver;

/**
 * query dsl 配置
 */
@Configuration
public class DataSourceQueryDslConfig {

    /**
     * 配置 query dsl 的前缀
     * @return
     */
    @Bean
    public EntityPathResolver entityPathResolver() {
        return new ProjectEntityPathResolver(".dsl");
    }

    public static class ProjectEntityPathResolver extends SimpleEntityPathResolver implements EntityPathResolver {

        /**
         * Creates a new {@link SimpleEntityPathResolver} with the given query package suffix.
         * @param querySuffix must not be {@literal null}.
         */
        public ProjectEntityPathResolver(String querySuffix) {
            super(querySuffix);
        }
    }
}

你可能感兴趣的:(spring,boot,jpa,querdsl)