小编San*_*eep的帖子

spring-boot:排除对包装的依赖性

我正在开发一个春季启动项目(项目A),该项目将包含在其他项目中(项目B,项目C ......).我在项目A中有几个依赖项,但在导入项目A的项目中,可能需要一些或仅一个.我正在尝试找到一种方法来在打包项目A时排除jar依赖项,以便在运行时由Project B提供所需的依赖项.我希望在项目A独立运行以进行测试时可以使用依赖项.

已经尝试过以下内容

我尝试过使用:

<scope>provided</scope>
<optional>true</optional>
Run Code Online (Sandbox Code Playgroud)

罐子里的最后一件神器仍然存在.

还尝试将以下内容添加到spring-boot-maven-plugin中

           <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                        <configuration>
                            <excludeArtifactIds>spring-boot-starter-redis</excludeArtifactIds>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
Run Code Online (Sandbox Code Playgroud)

这只会删除spring-boot依赖项,但是这个依赖项的子项的jar仍然会在最终的工件中结束.

java spring maven spring-boot

5
推荐指数
1
解决办法
1万
查看次数

在spring数据jpa存储库方法查询上附加自定义条件

精简版

我正在寻找一种方法来使存储库类的所有findBy方法附加特定条件

完整版本

我们假设我有一个产品实体和客户实体.它们都扩展了OwnerAwareEntity,并且它们继承了ownerRef字段,该字段标识了实体的所有者(它可以是商家或合作伙伴).我希望在运行时修改Product和Customer的findBy方法,以便附加ownerRef的附加条件.可以从用户会话中识别ownerRef值.

提供公共ownerRef字段的父实体类

public class OwnerAwareEntity implements Serializable {

 private String ownerRef;

}
Run Code Online (Sandbox Code Playgroud)

客户实体扩展了OwnerAwareEntity

public class Customer extends OwnerAwareEntity {

  private String firstname;

  private String mobile ;

}
Run Code Online (Sandbox Code Playgroud)

产品实体扩展了OwnerAwareEntity

public class Product extends OwnerAwareEntity {

  private String code;

  private String name;

}
Run Code Online (Sandbox Code Playgroud)

产品和客户的存储库类扩展了OwnerAwareRepository

public interface OwnerAwareRepository extends JpaRepository {

}

public interface ProductRepository extends OwnerAwareRepository {

  Product findByCode(String code );

}

public interface CustomerRepository extends OwnerAwareRepository {

  Customer findByFirstname(String firstname );

}
Run Code Online (Sandbox Code Playgroud)

这在执行时应该产生如下的查询

select P from Product …
Run Code Online (Sandbox Code Playgroud)

spring hibernate jpa spring-aop spring-data-jpa

3
推荐指数
1
解决办法
5282
查看次数