如何在 maven 多模块项目中使用 Spring ROO? [英] How to use Spring ROO with a maven multi-module project?

查看:87
本文介绍了如何在 maven 多模块项目中使用 Spring ROO?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 Spring Roo (1.2.4) 与 maven 多模块项目一起使用,但遇到了很多困难.我的实体在一个模块中声明,而 webapp 在另一个模块中声明.显然,webapp 将实体模块列为依赖项.

I'm trying to use Spring Roo (1.2.4) with a maven multi-module project and having a lot of difficulties. My entities are declared in one module and the webapp in another. Obviously the webapp has the entities module listed as a dependency.

但是,每当我在 webapp 中打开 ROO shell 时,我都无法为任何 @Roo 注释类型生成任何 Roo Aspects.例如,

However, whenever I open the ROO shell in the webapp, I cannot generate any of the Roo Aspects for any @Roo annotated type. For example,

@RooService(domainTypes = { com.ia.domain.User.class })

没有影响,除非我的 webapp 项目包含 com.ia.domain.User 类.如果我将该实体保存在单独的模块中,ROO 不会生成任何服务方面.如果我将实体添加到我的 webapp 项目中,ROO 将生成必要的方面:

has no impact unless my webapp project contains the com.ia.domain.User class. If I keep that entity in a separate module, ROO does not generate any of the Service aspects. If I add the entity to my webapp project, ROO will generate the necessary aspects:

Created SRC_MAIN_JAVA/com/ia/service/UserService_Roo_Service.aj
Created SRC_MAIN_JAVA/com/ia/service/UserServiceImpl_Roo_Service.aj

但是,一旦我从我的项目中删除了 User 类并将其保留在我的依赖项中,Roo 就会删除这些方面:

However, once I delete the User class from my project and leave it in my dependency, Roo deletes the aspects:

Deleted SRC_MAIN_JAVA/com/ia/service/UserService_Roo_Service.aj - empty
Deleted SRC_MAIN_JAVA/com/ia/service/UserServiceImpl_Roo_Service.aj - empty

是否有特殊的方式来配置 Roo 以支持多模块,或者这是 Roo 的限制?我是否因为这个项目而没有 Roo?

Is there a special way to configure Roo to support multi-modules, or is this a limitation of Roo? Am I stuck without Roo for this project?

推荐答案

所以在玩了几个小时的 ROO 和我的多 Maven 项目之后,发现了一些事情.

So after several hours of playing around with ROO and my multi-maven project and have discovered several things.

首先,尽管我很喜欢使用 Roo,但我仍然认为它还没有为企业级项目做好准备.Roo 似乎对 pom.xml 和 applicationContext.xml 文件的结构、设计和命名约定有太多限制和强加.

First and foremost, as much as I enjoyed using Roo, I still don't think that it is anywhere near ready for an enterprise level project. There seem to be too many limitations and impositions by Roo upon the structure, design and naming convention of pom.xml and applicationContext.xml files.

我的多模块项目结构如下:

My multi-module project had been structured as follows:

+ Project Root
    pom.xml (only lists modules)
  + parent-pom/
      pom.xml (pom: lists all the project-level dependency versions/plugin versions/etc
  + entities/
      pom.xml (jar: contains all the project's entities)
  + webapp/
      pom.xml (war: contains the BO and webapp design)

虽然这对 maven 来说很好,但对 Roo 来说却没有好处.为了让 Roo 将其视为一个多模块项目,我不得不对其进行如下重构:

Although this was fine for maven, it was no good for Roo. In order to get Roo to see this as a multi-module project working, I had to restructure it as follows:

+ Project Root
    pom.xml (lists all the project-level dependency versions/plugin versions/etc + modules)
  + entities/
      pom.xml (jar: contains all the project's entities)
  + webapp/
      pom.xml (war: contains the BO and webapp design)

不是最大的问题,但我宁愿让 parent-pom 作为它自己的工件与模块分离.不是 Roo 可以处理的.

not the biggest issue, but I would have rather had the parent-pom as its own artifact disassociated from the modules. Not something that Roo can handle.

此外,我不能让子项目继承父版本.我必须在每个模块中明确设置子版本,这样管理起来更费力,也不太干净.所以目前,我把每个孩子都定义为

Furthermore, I cannot have the child projects inherit the parent version. I have to explicitly set the child version in each module, which is more effort to manage, and a little less clean. So at the moment, I've defined each child as being

<version>${project.parent.version}</version>

这只是多余的,并且可能容易出现 maven-release-plugin 等错误.

which is just superfluous, and potentially prone to errors with the maven-release-plugin, etc.

此外,即使所有插件版本都在我父级的 <pluginManagement> 部分中定义,孩子们都需要在他们的 也是如此,这使得版本管理极其困难.事实上,看起来 几乎被 Roo 忽略了,因为甚至必须在每个子项中重复额外的配置.

Additionally, even though all the plugin versions are defined in my <pluginManagement> section in my parent, the children all need to have the versions specified in their <plugins> as well, which makes for extremely difficult version management. In fact, it would appear that the <pluginManagement> is all but ignored by Roo, as even additional configuration must be repeated in each child.

我对 Roo 最大的不满可能是我无法在 pom.xml 中指定我自己的版本.如果我想要 Roo 使用的库的特定版本,Roo 将覆盖我指定的任何版本,并将其设置为自己的版本.因此,如果我想使用较新版本的 Spring 库(例如:Spring-Data),每次我尝试创建存储库时,Roo 都会将其降级.

And probably my biggest pet peeve with Roo is that I cannot specify my own versions in my pom.xml. If I want a specific version of a library used by Roo, Roo will override whatever version I have specified, and set it's own version in place. So if I want to use a more recent release of a Spring lib (ex: Spring-Data), Roo will keep downgrading it every time I try to create a Repository.

这一切只是为了让 Roo 将项目视为一个多模块项目.既然是可见的,我发现我只能在父级打开shell.如果我在孩子身上打开 Roo 外壳,它将删除我在原始帖子中提到的任何 Roo 方面.我需要在父级上打开 Roo shell,然后使用

All that was just to get Roo to see the project as a multi-module project. Now that it is visible, I discovered that I can only open the shell at the parent level. If I open a Roo shell on a child, it will delete any Roo aspects as mentioned in my original post. I need to open the Roo shell on the parent, and then use

module focus --moduleName entities 

为孩子工作.这意味着我总是需要在 Eclipse/STS 中打开/导入父项目,这可能并不总是我想做的事情.

to work on the child. Which implies that I always need to have the parent project opened/imported in Eclipse/STS which may not always be something I want to do.

下一个限制是,即使我切换到实体模块,Roo 也不会使用 entity jpa --class ~.domain.User 为我创建实体,因为 Roo 不理解我的 jpa设置是在我的 webapp 模块中完成的.所以我只能在与 jpa 设置相同的模块中创建我的实体.

Next limitation is that even if I switch to the entities module, Roo will not create entities for my there using entity jpa --class ~.domain.User as Roo does not understand that my jpa setup was done in my webapp module. So I am limited to creating my entities in the same module as my jpa setup.

关于我的 JPA 设置,我将 Spring 配置为不使用 persistence.xml 文件,而是仅使用 LocalContainerEntityManagerFactoryBean:

With respect to my JPA setup, I configured Spring to not use the persistence.xml file, and instead just use the LocalContainerEntityManagerFactoryBean:

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter"/>
        <property name="packagesToScan" value="com.ia.domain"/>
        <property name="jpaProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop>
                <prop key="hibernate.query.substitutions">true '1', false '0'</prop>
                <prop key="hibernate.generate_statistics">true</prop>
                <prop key="hibernate.show_sql">false</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop>
                <prop key="hibernate.connection.charSet">UTF-8</prop>
            </props>
        </property>
    </bean>

Roo 不喜欢那样,并坚持拥有一个 persistence.xml 文件、一个 applicationContext-jpa.xml 文件、一个 database.properties 文件(即使我希望我的所有数据库配置都通过 JNDI)和我的 applicationContext.xml 文件中的事务配置,即使我已经在 applicationContext 中定义了我的所有配置-hibernate.xml 文件.可能不是最大的问题,但我不喜欢 Roo 强迫我的手并强加我的 applicationContext 文件的特定布局的事实.如果我想给他们取不同的名字,我什至都做不到.

Roo does not like that, and insists on having a persistence.xml file, an applicationContext-jpa.xml file, a database.properties file (even though I want all my DB configuration to be via JNDI) and transaction configuration within my applicationContext.xml file, even though I already had all my configuration already defined in an applicationContext-hibernate.xml file. Probably not the biggest issue, but I don't like the fact that Roo is forcing my hand and imposing a specific layout of my applicationContext files. If I wanted to call them something different, I wouldn't even be able to.

总的来说,我发现 Roo 使用起来很有趣,但所有这些限制让我意识到它只是不适合大型项目开发.即使我没有使用 Tiles2,我什至无法让它停止为 Tiles2 生成视图!

Overall, I have found Roo to be fun to use, but all these limitations make me realize that it is just not ready for large project development. I wasn't even able to get it to stop generating views for Tiles2 even though I am not using Tiles2!

如果有办法自定义/配置 Roo 以避免这些我没有发现的陷阱,我会很高兴听到它们.

If there are ways to customize/configure Roo to avoid these pitfalls that I haven't discovered, I would be happy to hear about them.

这篇关于如何在 maven 多模块项目中使用 Spring ROO?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆