可以逐步迁移Java所需的JavaEE是否需要Spring?

问题描述 投票:1回答:1

我们有一个现有的Vaadin 8 JavaEE webapp,它已经过Tickets Dashboard演示的调整和大量修改。我们正在计划一个计划,将应用程序迁移到使用Spring(非启动)并采用MVC模型用于下一个版本。但是,在阅读了Vaadin Spring文档并比较当前应用程序,样本烘焙应用程序(spring,使用Framework 8)和使用Hibernate 4和Spring 4的旧项目之间的源代码之后,我们仍然有一些关键问题,需要帮助改进我们的迁移方法:

  1. 是否可以逐步迁移,其中一些功能首先迁移到Spring,然后是其他次要版本中的其他功能?如果是,在进入较小的版本之前,我应该首先将哪些类修改/改编(除了以下那些)到Spring之前?
  2. 我们已经确定75%的应用程序使用复杂的本机选择查询,其中25%用于CRUD操作。我们仍然坚持使用Hibernate,因为大多数开发团队都熟悉它。是否更好地坚持使用DAO泛型方法(封装实现,例如https://www.baeldung.com/simplifying-the-data-access-layer-with-spring-and-java-generics)或仅使用Baker应用程序中看到的JPARepository接口?
  3. 我们将应用程序部署到Azure云中,使用TomEE Plume(相当于Tomcat的8.5)作为启动部署。是否应该包含任何特殊设置以适应该部署?

我们之前在Vaadin论坛上提出了关于逐步迁移的问题,但没有任何回复:https://vaadin.com/forum/thread/17468362/17468363

计划的移民活动后我们的近期目标是:

  1. 使其模块化,更容易整合后续功能,如动态数据路由,断路器/重新路由,电子邮件通知,国际化,将可管理实例的数量保持在生产级别的5-10等。
  2. 保持开放升级的途径,而不必在未来几年内从头开始重写所有内容,例如(Java 8到Java 11,Framework 8到Vaadin 12)。

如上所述,这适用于使用MSSQL数据库和TomEE Plume容器在Azure Cloud上运行。

我们做了一些初步的代码修改,包括:

  1. 修改主pom.xml并包含更好的maven profiling(使用https://www.mkyong.com/maven/maven-profiles-example/作为参考)
  2. 将休眠和弹出设置移动到application.properties文件
  3. 添加了application-context.xml并将其再次划分为application-context-dao.xml和application-context-service.xml以使其易于管理。

网嗯

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:applicationContext.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>

<servlet>
    <servlet-name>SycardaDashboard2</servlet-name>
    <servlet-class>com.example.dashboard.DashboardServlet</servlet-class>
    <init-param>
        <param-name>UI</param-name>
        <param-value>com.example.dashboard.DashboardUI</param-value>
    </init-param>
</servlet>
<servlet-mapping>
    <servlet-name>SycardaDashboard2</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

应用程序的context.xml

<beans>
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>classpath*:application-development.properties</value>
                <value>classpath*:application-production.properties</value>
            </list>
        </property>

    </bean>
<import resource="classpath*:applicationContext-dao.xml" />
<import resource="classpath*:applicationContext-service.xml" />

<context:component-scan base-package="com.example.dashboard">
    <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan>
</beans>

应用道的context.xml

<!-- Activates scanning of @Autowired -->
<context:annotation-config/>

<!-- Activates scanning of @Repository -->
<context:component-scan base-package="com.igi.sycarda.dashboard.dao"/>

<bean class="org.springframework.orm.hibernate4.HibernateExceptionTranslator"/>
<bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>

<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean" destroy-method="destroy">
    <property name="dataSource" ref="dataSource" />
    <property name="packagesToScan">
        <list>
            <value>com.example.dashboard.entities</value>
        </list>
    </property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
            <prop key="hibernate.query.substitutions">true 'Y', false 'N'</prop>
            <prop key="hibernate.cache.use_second_level_cache">true</prop>
            <prop key="hibernate.cache.use_query_cache">true</prop>
            <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</prop>
            <prop key="current_session_context_class">thread</prop>

            <prop key="show_sql">${hibernate.show.sql}</prop>
            <prop key="format_sql">${hibernate.format.sql}</prop>
            <prop key="use_sql_comments">${hibernate.use.sql.comments}</prop>
        </props>
    </property>
</bean>

<!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
<bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory"/>
</bean>

首先,在迁移的第一周之后,我们希望应用程序仍然是90%的JavaEE,并且一个或两个函数将在Spring中。在每周更新之后,现有功能的数量将转变为使用Spring,直到完全合并为止。

java spring hibernate vaadin vaadin8
1个回答
1
投票

这种迁移是可能的。你在问题中有多个问题,我只回答其中两个问题。

  1. 渐进式迁移是否可行?是的,它是可能的,您可以将它首先放在底层 - 在复杂的整体结构中你的DAO和存储库。或者您可以尝试将应用程序分成小的逻辑单元并尝试迁移这些单元。如果我们为电子商务网站提供计算商品价格的服务,那么这种切片的示例就是如此。这是一个明确定义的服务,可以很容易地隔离。采用这种方法还可以让您更好地了解模块化应用程序的方式。有时虽然这种方法对于巨大的整体而言可能太难了,而代码只是sphagetti。
  2. Spring数据的使用和现有Daos的迁移。使用spring-data不是必须的。拥有DAOS或手动编写的存储库是完全没问题的。在我看来,不需要付出额外的努力,或者做这种迁移的额外工作。

IMO是迁移过程中的主要目标,应该进行合理的模块化,并将整体块分成逻辑单元。我不是在谈论单独的可部署和微服务,所以没有必要这么做。但逻辑上拆分它可能会为您提供迁移映射。

© www.soinside.com 2019 - 2024. All rights reserved.