Spring MVC迁移Spring Boot:XML配置转application.properties求助
Spring MVC转Spring Boot:XML配置转application.properties的后续问题
最近我在把一个老的Spring MVC项目迁移到Spring Boot,已经搞定了JDBC和JSP相关的配置,转成了application.properties里的内容,但还有几块XML配置不知道怎么对应过去,想请教下大家的思路和具体配置方法。
原XML里待转换的配置
这是我还没处理的Spring MVC XML配置片段:
<bean id="trans" class="org.springframework.orm.hibernate5.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> </bean> <tx:annotation-driven transaction-manager="trans" /> <mvc:resources location="/resources/" mapping="/resources/**"></mvc:resources>
已经完成的application.properties配置
目前已经配置好的内容如下:
spring.jpa.hibernate.ddl-auto=update spring.datasource.url=jdbc:mysql://localhost:3306/?useSSL=false spring.datasource.username=root spring.datasource.password=asdf spring.datasource.driver-class-name=com.mysql.jdbc.Driver spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect spring.mvc.view.prefix:/WEB-INF/views/ spring.mvc.view.suffix:.jsp
已尝试的部分代码
我找到了一段获取SessionFactory的配置类,但不确定对应的application.properties有没有补充配置,也不知道剩下的事务、静态资源该怎么处理:
@Configuration public class HibernateConf { @Autowired private EntityManagerFactory entityManagerFactory; @Bean public SessionFactory getSessionFactory() { return entityManagerFactory.unwrap(SessionFactory.class); } }
想请教的问题
希望能得到以下内容的实现思路:
- 原XML中
HibernateTransactionManager和<tx:annotation-driven>该怎么转换成Spring Boot的配置?有没有对应的application.properties项? <mvc:resources>对应的application.properties配置项是什么?- 上面这段SessionFactory的配置类是否需要调整?有没有需要补充的配置?
内容的提问来源于stack exchange,提问作者johnstreip
相关产品推荐
相关产品推荐

