从war maven

时间:2017-07-18 17:08:18

标签: java hibernate maven batch-file maven-assembly-plugin

我正在将我的java Web应用程序打包到包含所有依赖项和其他东西的zip文件中...使用maven程序集插件,我编写了一个批处理脚本,以便部署战争并在不打开eclipse的情况下运行它。

这里的问题是我想为其他计算机上的其他数据库运行这个批处理文件,在这里我需要你的帮助告诉我是否有办法外化hibernate.cfg.xml直接配置数据库给谁我的申请将链接到。

提前致谢

2 个答案:

答案 0 :(得分:0)

您需要配置property文件以外部化hibernate.cfg.xml。在类路径中创建hibernate.properties并为hibernate的配置设置变量和值。你可以参考下面的示例代码:

hibernate.cfg.xml中:     

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="hibernateProperties">
       <map>
            <entry key="connection.driver_class" value="${hibernate.connection.driver_class}" />
            <entry key="connection.username" value="${hibernate.connection.username}" />
            <entry key="connection.password" value="${hibernate.connection.password}" />
            <entry key="transaction.factory_class" value="org.hibernate.transaction.JDBCTransactionFactory" />
        </map>
    <property>
 </bean>

hibernate.properties:

hibernate.connection.driver_class = com.mysql.jdbc.Driver
hibernate.connection.url = jdbc:mysql://localhost:3306/test
hibernate.connection.username = root
hibernate.connection.password = root
hibernate.dialect = org.hibernate.dialect.MySQLDialect
hibernate.current_session_context_class=thread

答案 1 :(得分:0)

我发现我必须在hibernate.properties中指定连接属性(用户名,密码,connection.url,方言......)。 类映射必须保留在hibernate.cfg.xml文件中。 通过将它们放在resources,Hibernate将找到它们并提取他需要的东西:D