首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使cxf-codegen-plugin生成的类具有持久性。

使cxf-codegen-plugin生成的类具有持久性。
EN

Stack Overflow用户
提问于 2017-06-16 12:21:26
回答 1查看 378关注 0票数 0

我有一个Maven jar项目,它使用cxf-codegen-plugin创建了一个SOAP客户机。

在使用该客户端的另一个Maven项目中,只需使用JPA (当前使用OpenJPA)来持久化由cxf-codegen-plugin生成的数据类实例(一些soap响应)。

在每个客户端源代码生成之后,在编译/增强和安装客户端jar之前,可能需要在数据类中添加@Entity注释,但我想摆脱这个阶段,同时保持客户机尽可能的泛型。使用客户端的项目应该能够安全地假设类具有持久性能力。

处理这一问题的最佳方法可能是在客户端项目设置中使用一些技巧(目前使用openjpa plugin来增强数据类)来检测所需的类,并以某种方式使它们具有持久性和增强这些类的能力。

我宁愿跳过一些东西,比如维护beans.xml,如果可能的话坚持使用注释,但这也是一种选择。

EN

回答 1

Stack Overflow用户

发布于 2017-10-15 10:00:54

如果有人需要同样的方法,我将描述我目前使用的方法。它基于添加注释,如使用idimportscom.google.code.maven-replacer-plugin字段。

简短:我在我的pom.xml中添加了以下内容

代码语言:javascript
复制
<plugin>
    <groupId>com.google.code.maven-replacer-plugin</groupId>
    <artifactId>replacer</artifactId>
    <version>1.5.3</version>
    <executions>
        <execution>
            <phase>process-sources</phase>
            <goals>
                <goal>replace</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <!-- dir where cxf-codegen-plugin has generated model classes -->
        <basedir>src/generated/java/org/example/service</basedir>
        <includes>
            <include>NamedEntity.java</include>
        </includes>
        <regex>false</regex>
        <replacements>
            <replacement>
                <token>package org.example.service.service;</token>
                <value>package org.example.service.service;

                    import javax.persistence.Id;
                    import javax.persistence.Entity;
                    import javax.persistence.Inheritance;
                    import javax.persistence.GeneratedValue;
                    import javax.persistence.InheritanceType;

                </value>
            </replacement>
            <replacement>
                <token>public class</token>
                <value>@Entity
                    @Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)
                    public class</value>
            </replacement>
            <replacement>
                <token>protected String name;
                </token>
                <value>protected String name;

                    @Id
                    @GeneratedValue
                    @Getter
                    private Long id;

                </value>
            </replacement>
        </replacements>
    </configuration>
</plugin>

为了保持代码的良好格式化,需要在<replacement>中使用所有缩进和行提要。使用regexp可以做得更时髦,但这对我来说已经足够好了。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44589147

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档