java - Spring-boot applicationDatasource.xml 未从外部属性读取
问题描述
我正在尝试从外部属性读取数据源 JNDI,但显然它无法读取它。
我试过这个:
<jee:jndi-lookup id="clarifyDS" jndi-name="${bd.clarify.jndi}"
lookup-on-startup="false" proxy-interface="javax.sql.DataSource" />
但它会引发以下错误。
SERVER: AdminServer [ERROR] [08-07-2019 14:16:18.088] (ClarifyDaoImpl.java:120) - [ obtenerColasAsoc idTx= ] - [obtenerColasAsoc]JndiObjectTargetSource failed to obtain new target object; nested exception is javax.naming.NameNotFoundException: While trying to lookup '${bd.clarify.jndi}' didn't find subcontext '${bd'. Resolved ''; remaining name '${bd/clarify/jndi}'-org.springframework.jndi.JndiLookupFailureException: JndiObjectTargetSource failed to obtain new target object; nested exception is javax.naming.NameNotFoundException: While trying to lookup '${bd.clarify.jndi}' didn't find subcontext '${bd'. Resolved ''; remaining name '${bd/clarify/jndi}'
我只需要数据源的名称,因为这是在 weblogic 服务器上配置的。无需用户名或密码。
这是完整的文件
应用程序上下文.xml
<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.1.xsd">
<context:annotation-config />
<context:component-scan base-package="pe.com.claro.postventa.consultacolas" />
<context:property-placeholder location="file:${file.properties}ConsultaColas/.properties" />
<import resource="applicationDatasource.xml" />
</beans>
应用程序数据源.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.1.xsd">
<jee:jndi-lookup id="clarifyDS" jndi-name="${bd.clarify.jndi}"
lookup-on-startup="false" proxy-interface="javax.sql.DataSource" />
</beans>
这是我的Java类。
@Repository
public class ClarifyDaoImpl implements ClarifyDao{
private static final Logger logger = Logger.getLogger(ClarifyDaoImpl.class);
@Autowired
@Qualifier(value = "clarifyDS")
private DataSource clarifyDS;
@Autowired
Propiedades propiedades;
private Utilitarios utilitarios = new Utilitarios();
@Override
public ObtenerColasAsocResponseBean obtenerColasAsoc(String mensajeTransaccion, ObtenerColasAsocRequestBean request)
throws DBException {
//Do something
}
}
也许我没有使用正确的语法来读取属性文件
顺便说一句,如果有人知道我很高兴听到的更好方法,我不确定这是否是将 conexion 设置为数据库的最佳方法。
谢谢!
解决方案
推荐阅读
- javascript - 无法读取未定义的属性“片段”
- c# - 使用 LINQ 替换 C# 中可枚举的一个元素
- azure - 用于扩展 RU 的 Cosmos DB 存储过程
- python - 为什么当我创建一个新的工人时,以前的芹菜工人的任务仍然存在?
- django - CreateView 不创建任何对象
- javascript - 使用 node.js fs.readStream() 在电子 html5 视频播放器中播放本地视频文件
- c# - C# .NET CORE:如果返回某种结果,则取消其他任务
- java - 线程转储的原因:转储事件“systhrow”(00040000)收到详细信息“java/lang/OutOfMemoryError”“Java 堆空间”
- asp.net-core - ASP.NET Core Razor 页面在回发时保留显示数据
- python - 搜索
- 通过子文本列出