How to use Spring ROO with a maven multi-module project?

♀尐吖头ヾ 提交于 2020-01-16 06:58:26

问题


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.

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 })

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

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

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?


回答1:


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

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)

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)

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>

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

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.

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.

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 

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.

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.

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 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.

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!

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.



来源:https://stackoverflow.com/questions/22084549/how-to-use-spring-roo-with-a-maven-multi-module-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!