Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring引导:未能将JNDI变量加载到yml配置文件中_Spring_Spring Boot_Yaml_Jndi - Fatal编程技术网

Spring引导:未能将JNDI变量加载到yml配置文件中

Spring引导:未能将JNDI变量加载到yml配置文件中,spring,spring-boot,yaml,jndi,Spring,Spring Boot,Yaml,Jndi,根据,我尝试将JNDI变量加载到yml配置文件中,如下所示: spring: # Show or not log for each sql query jpa: show-sql: java:global/bc-api-immop/hibernate/show_sql 但它不起作用 我的JNDI上下文中有我的变量: 我也试过: spring: # Show or not log for each sql query jpa: show-sql jn

根据,我尝试将JNDI变量加载到yml配置文件中,如下所示:

spring:
  # Show or not log for each sql query
  jpa:
    show-sql: java:global/bc-api-immop/hibernate/show_sql
但它不起作用

我的JNDI上下文中有我的变量:

我也试过:

spring:
  # Show or not log for each sql query
  jpa:
    show-sql
      jndi-name: java:global/bc-api-immop/hibernate/show_sql
但是,结果还是一样的。 你知道我做错了什么吗

听起来很奇怪,我也有这样的代码,它可以工作:

spring:
  # Set here configurations for the database connection
  datasource:
    jndi-name: java:jboss/datasources/bc-appli-as400-ds
编辑:当我这样做时,它会起作用(因此我的问题实际上来自获取JNDI变量):


你写yaml的方式才是真正的问题

一般的概念是
key:value
,因此,通过编写
show sql
spring boot,当值出现时,它期望值为
true
false
,因此属性配置失败是正常的,我很确定这会显示在日志文件中的某个位置

在第一个例子中,当您编写
showsql:java:global/bcapi imop/hibernate/show_sql
时,您实际上是在用“Hi-spring Boot这是您的数据源”来回答“我应该向您显示生成的sql语句吗?”的问题,我们都知道这与spring Boot没有任何关系:)

另一方面,你最后的陈述是正确的。您正在yaml集合项
datasource
下定义属性
jndi name:
和值
java:jboss/datasources/bc-appli-as400-ds

我还建议花10分钟阅读这篇文章

因此,正确的方法可能是

spring:
  # Set here configurations for the database connection
  datasource:
    jndi-name: java:jboss/datasources/bc-appli-as400-ds
  jpa:
    show-sql: true

如果我能为您提供更多帮助,请告诉我。谢谢您的回答。事实上,你最后的建议就是我的建议。但是现在,我想根据我的JNDI变量将事实配置为显示(或不显示)SQL。我不明白的是,为什么在“showsql”之后加上“jndiname”属性会失败。这是不可能的。JNDI变量将为您提供连接。showsql指的是JPA实现,它与实际连接无关。我想我错过了一些关于你想做什么的事情。顺便说一句,如果你喜欢我的答案,请标记为可以接受:)
spring:
  # Set here configurations for the database connection
  datasource:
    jndi-name: java:jboss/datasources/bc-appli-as400-ds
  jpa:
    show-sql: true