我有两个项目:
/src/main/resources/schema.xsd pom.xml
B/src/main/gen pom.xml
我想在B项目中生成来自XSD的类,它存在于A Project中
在B项目的pom.xml中我有:
<dependencies>
<dependency>
<groupId>test</groupId>
<artifactId>A</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>src/main/resources</schemaDirectory>
<outputDirectory>src/main/gen</outputDirectory>
</configuration>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud)
但是在类路径中找不到xsd文件:
无法在项目B上执行目标org.codehaus.mojo:jaxb2-maven-plugin:1.5:xjc(xjc):未找到任何模式
如何使用其他项目的xsd?
Repository和Service应该如何分离?恕我直言,客户端(例如控制器)应该主要使用服务层而不是存储库,因为它应该与持久性实现分开。Single Repository 应该只提供一个实体的访问方法,而 Service 的方法能够提供更复杂的操作,包括使用多个存储库。
但是如何处理丰富的存储库,它不仅提供 CRUD 方法,而且提供更多,例如 Spring Data 中的 JPARepository?在这样的实现中,有很多可能的获取对象的方法,在 Service 中复制它们并不酷。
那么这个问题的解决方案是什么?
A. 像这样在服务层重复方法
@Service
class XService{
@Autowired
private XRepository repository;
public List<X> findAll(){
return repository.findAll();
}
}
Run Code Online (Sandbox Code Playgroud)
B. 简单地在控制器中使用存储库(自动装配或服务中的访问方法)
C. 还有其他好的方法吗?