我花了太多时间在连接一些JNDI工厂bean时试图找出一些错误.结果问题是,而不是......
<bean id="someId" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/loc"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
我其实写了这个......
<bean id="someId" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/loc"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
我推断java:comp/env /可能引用了一些环境变量,并最终使我的上下文文件被查看.唯一的区别是java:comp/env /.从专家的口中,这是做什么的?
如果没有值中的java:comp/env前缀,我将收到一条错误,指出"Name jdbc未绑定在此Context中".
我有一个JSF Web应用程序,我想使用嵌入式tomcat运行.它到目前为止[包括JDBCRealm,在以下代码片段的context.xml中指定],除了登录后我的代码无法实际获取源中指定的连接资源,抛出NoInitialContextException.
我可能错过了一些明显的东西,但是关于tomcat嵌入的似乎很少有流量.[Tomcat7.0.47,JDK7].
由于每其他问题在这个网站上这个网站,我已经尝试了多种变体上添加一个初始环境,但我一直无法弄清楚,如果这真的是我的问题,还是我只是还没有找到合适的这个tomcat服务器的咒语.
Tomcat启动代码:
tomcat = new Tomcat();
tomcat.setPort(port);
tomcat.setBaseDir(".");
Context ctx = tomcat.addWebapp("/" + appname, appname);
// The login realm specified in this XML file is a JDBC realm, and the server correctly logs users in, so I believe this is parsed.
ctx.setConfigFile(new URL("file:///home/chunky/src/aqmt/AQMTEmbed/webapps/AQMTWeb/META-INF/context.xml"));
ContextResource resource = new ContextResource();
resource.setName("jdbc/aqmtwebdb");
resource.setAuth("Container");
resource.setType("javax.sql.DataSource");
resource.setScope("Sharable");
resource.setProperty("driverClassName", "com.mysql.jdbc.Driver");
resource.setProperty("url", "jdbc:mysql://localhost:3306/aqmtweb?autoreconnect=true");
resource.setProperty("username", "username");
resource.setProperty("password", "password");
ctx.getNamingResources().addResource(resource);
tomcat.start();
Run Code Online (Sandbox Code Playgroud)
在Web应用程序本身是这样的:
InitialContext ctx = new InitialContext();
// This line …
Run Code Online (Sandbox Code Playgroud)