springmvc+hibernate5 不能自动建表

搭建了项目框架,创建了*.hbm.xml文件后,运行项目,没能和预想的一样自动建表,配置文件如下所示:

<!--配置hibernate的SessionFactory-->
<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
    <!--注入数据源-->
    <property name="dataSource" ref="dataSource" />
    <property name="mappingLocations" value="classpath:com/step/entity/hbm/*.hbm.xml"/>
    <!--hiberate配置信息-->
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">${hibernate.dialect}</prop>
            <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
            <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
            <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
            <!-- 开启二级缓存 ehcache -->
            <prop key="hibernate.cache.use_second_level_cache">${hibernate.cache.use_second_level_cache}</prop>
            <prop key="hibernate.cache.use_query_cache">${hibernate.cache.use_query_cache}</prop>
            <prop key="hibernate.cache.region.factory_class">${hibernate.cache.region.factory_class}</prop>
            <prop key="hibernate.cache.provider_configuration_file_resource_path">${hibernate.cache.provider_configuration_file_resource_path}
            </prop>
        </props>
    </property>
    <!--扫描hibernate注解配置的entity-->
    <!--<property name="packagesToScan" value="com.experiment.Entity" />-->
</bean>

<!--配置事务管理器-->
<bean id="transactionManager" class="org.springframework.orm.hibernate5.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

编译运行,没有报错也没能正常建表,故意改错User.hbm.xml中的name值,将id改为myId,编译,没有报错,判断是文件地址问题,尝试了很多方式,并没有解决,抱着怀疑的心态看了一下编译目录,发现hbm文件夹是空的!空的!空的!也就是说,项目在编译的时候,*.hbm.xml文件并没有发布。手动将文件复制到编译目录下,重新运行后可以自动建表了。
查了一下发现解决IntelliJ IDEA Maven项目在编译发布时候 .xml不发布的的办法(原文地址),即在*.pom文件中添加build resources的方式发布src/main下面的资源文件:

<build>
    <finalName>step</finalName>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.xml</include>
            </includes>
            <filtering>false</filtering>
        </resource>
    </resources>
</build>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值