【问题标题】:Java AWS MySQL & hibernateJava AWS MySQL 和休眠
【发布时间】:2018-07-08 00:28:45
【问题描述】:

第一次在这里问问题,长期使用通过这里在谷歌上寻找答案!我已经开始为一家公司发起编码挑战。我完成了挑战并让它满足他们的要求。它现在只需要托管在 AWS 上即可。我将它托管到 AWS,但 AWS 似乎无法使用或找到我的 cfg.xml 文件。我无休止地阅读并观看了 youtube 教程,但似乎找不到我的答案。

我已经设置了一个 RDS 和一个镜像我可以通过 tomcat 在本地托管的表的表。但看来我现在必须做一些事情才能将休眠路由到数据库。

HTTP 状态 500 – 内部服务器错误 输入异常报告

消息请求处理失败;嵌套异常是 org.hibernate.internal.util.config.ConfigurationException: 找不到 cfg.xml 资源 [hibernate.cfg.xml]

当页面尝试从 AWS 访问数据库时出现错误,正如我提到的,当我通过 eclipse 启动它时它工作正常。我想我必须对 hibernate.cfg.xml 文件做一些事情,只是不确定如何使其适应 AWS。帮助将不胜感激!谢谢

    <?xml version='1.0' encoding='utf-8'?>

<session-factory>


    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/schema</property>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.username">un</property>
    <property name="hibernate.connection.password">pw</property>
            <property name="show_sql">true</property>

    <mapping class="com.dto.RegisteredUserDto"></mapping>
    <mapping resource="RegisteredUserDto.hbm.xml"></mapping>


</session-factory>

【问题讨论】:

  • 你能确认 hibernate.cfg.xml 文件在 src/main/resources 中的位置吗?

标签: java mysql spring hibernate amazon-web-services


【解决方案1】:

如果您使用 Maven 构建项目,请将 hibernate.cfg.xml 文件放在 src/main/resources 下。

请参考 hibernate.cfg.xml 的位置

Location of hibernate.cfg.xml in project?

【讨论】:

  • 明白了。我的直接在 src 文件夹下。你认为这是原因吗?
【解决方案2】:

解决了。不确定是否有错字。但是我用新的 RDS 在 AWS 中创建了一个新实例。我在mysql的这个连接下再次创建了表。我用新的 url 更新了我的休眠文件。更新了我的 AWS。而且效果很好。

【讨论】:

    猜你喜欢
    • 2012-05-10
    • 2011-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-27
    • 1970-01-01
    • 1970-01-01
    • 2018-03-12
    相关资源
    最近更新 更多