Tomcatを埋め込んだまま実行したいJSF Webアプリケーションがあります。ログイン後、コードがソースで指定された接続リソースを実際に取得できず、NoInitialContextExceptionをスローすることを除いて、これまでのところ[[次のコードスニペットのcontext.xmlに指定されたJDBCRealmを含む]]が動作しています。埋め込み:データソースを取得しようとしたときにNoInitialContextExceptionが発生しました
私は恐らく何かが分かりませんが、そこにはTomcatが埋め込まれていることについてのトラフィックはほとんどないようです。 [Tomcat7.0.47、JDK7]。
このサイト上this site上の他のquestionsperとして、私は初期環境を追加することでバリエーションの数を試みたが、私はそれが本当に私の問題だかどうかを把握することができていない、または私は持っていませんまだこのTomcatサーバーのための正しい命題を見つけました。
Tomcatの起動コード:
InitialContext ctx = new InitialContext();
// This line here throws the exception:
DataSource webds = (DataSource)ctx.lookup("java:/comp/env/jdbc/aqmtwebdb");
スローされた例外がある:
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at org.rand.aqmt.UserBean.<init>(UserBean.java:77)
[ラインUserBean.java:77 Webアプリケーション自体に
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();
はこれです上記のctx.lookup()です]
私はかなり進歩する方法を失っています。
素晴らしい、ありがとう! – icyitscold
+100。 Re man、私はちょうどその愚かな事のために1日半を失ったし、私はあなたのポストに来ていない場合、私は人生を失っているかもしれない...おかげでトン。 –