在现有应用程序中,我使用 jndi 连接到数据库,如下所示。请指导我如何在基于 Spring 的应用程序中编写有效的代码。
我当前的 jndi 查找代码是
InitialContext context = null;
String welcomeMessage = null;
Integer maxSessionCount = null;
try{
context = new InitialContext();
welcomeMessage = (String)context.lookup(
"java:comp/env/welcomeMessage");
maxSessionCount = (Integer)context.lookup(
"java:comp/env/maxSessionCount");
}
catch (NamingException exception){
exception.printStackTrace();
}