mongodb - Grails 3 MongoDB无法从application.yml中读取con

我正在测试Grail 3应用程序以连接在另一台服务器上运行的mogoDB。

独立的Java程序成功连接到数据库。但是Grail 3应用程序无法连接到DB。异常显示其连接到本地主机。

我想了解为什么它不从aplication.yml文件读取连接字符串。

application.yml文件:

environments:
    development:
        grails:
            mongodb:
                connectionString: "mongodb://192.168.1.13:27017/test"

当我访问页面时,看到此错误消息。
grails> 2017-02-14 22:52:28.116 ERROR --- [nio-8080-exec-9] o.g.web.errors.GrailsExceptionResolver   : MongoTimeoutException occurred when processing request: [GET] /book/index
Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers=[{address=127.0.0.1:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: Connection refused: connect}}]. Stacktrace follows:

为什么它连接到本地主机?

从这个答案尝试不起作用。

Installing and using MongoDB in Grails 3.x

谢谢

最佳答案

此配置在开发和生产中都对我有用。

environments:
development:
    grails:
        mongodb:
            host: "localhost"
            port: 27017
            username: ""
            password: ""
            databaseName: "mydb-dev"
production:
    grails:
        mongodb:
            host: "1.1.1.1"
            # host: "localhost"
            port: 27017
            username: ""
            password: ""
            databaseName: "mydb-prod"

我正在使用Grails 3.1.9和最新的MongoDB插件。
compile 'org.grails.plugins:mongodb'

关于mongodb - Grails 3 MongoDB无法从application.yml中读取connectionString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42250837/

相关文章:

bash - SSH隧道复杂问题

grails - 访问 Grails 全局变量时是否需要使用互斥锁?

grails - 如何在Grails(2.5.5)中自动在前面带有多个大写字母的服务接线

unit-testing - 基于 Spock 交互的测试 : too few invocation

pdf - 生成的pdf中的文本是反向的

colors - 在 ssh 之前导出 TERM

grails - Grails从1.3.7升级到3.2.6的路径

svn - 通过SSH的svn diff-结果与Trac不同吗?

grails - repo.grails.org - 证书过期

ssh - 如何测量 SSH 隧道的带宽?