我正在尝试从外部属性读取数据存储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服务器上配置的。不需要用户名或密码。
这是完整的文件
applicationContext.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>
applicationDatasoruce.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
}
}
也许我没有使用正确的语法读取属性文件
顺便说一句,如果有人知道我乐于听到更好的方法,那么我不确定这是否是将共轭设置为数据库的最佳方法。
谢谢!