" javax.naming.NameNotFoundException;剩下的名字&env / jdbc / myds' "当我使用jaas获取DataSource时出现

时间:2015-01-23 01:55:52

标签: datasource jndi jaas jetty-9

我使用jetty 9.2.2.v20140723作为服务器。 我使用jetty-maven-plugin,像这样的pom.xml:

    <plugin>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <version>9.2.2.v20140723</version>
        <configuration>
            <systemProperties>
                <systemProperty>
                     <name>java.security.auth.login.config</name>
                     <value>props.conf</value>
                 </systemProperty>
            </systemProperties>
            <!-- <scanIntervalSeconds>3</scanIntervalSeconds> -->
            <connectors>
                <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
                    <port>8080</port>
                </connector>
                <connector implementation="org.eclipse.jetty.server.ssl.SslSocketConnector">
                    <port>8443</port>
                    <keystore>keystore.jks</keystore>
                    <keyPassword>password</keyPassword>
                    <password>password</password>
                    <needClientAuth>false</needClientAuth>
                    <wantClientAuth>false</wantClientAuth>
                </connector>
            </connectors>
        </configuration>
    </plugin>
像这样的

jetty-env.xml:

  <Configure id="wac" class="org.eclipse.jetty.webapp.WebAppContext">
  <New id="myds" class="org.eclipse.jetty.plus.jndi.Resource">
     <Arg><Ref refid="wac"/></Arg>
     <Arg>jdbc/myds</Arg>
     <Arg>

        <New class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource">
           <Set name="Url">jdbc:mysql://localhost:3306/cp</Set>
           <Set name="User">root</Set>
           <Set name="Password">1234</Set>
        </New>
     </Arg>
 </New>
</Configure>

像这样的web.xml:

<resource-ref>
    <description>My DataSource Reference</description>
    <res-ref-name>jdbc/myds</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

当我这样登录时:

ctx = new LoginContext("props", new TestCallBackHandler(username, password));
ctx.login();

我收到错误:

javax.security.auth.login.LoginException: java.lang.IllegalStateException: javax.naming.NameNotFoundException; remaining name 'env/jdbc/myds'

但是我可以得到这样的数据源:

InitialContext ctx = new InitialContext();
            DataSource ds = (DataSource)ctx.lookup("java:comp/env/jdbc/myds");

1 个答案:

答案 0 :(得分:0)

是Vaadin问题,我改变了“@Push”