【问题标题】:"javax.naming.NameNotFoundException; remaining name 'env/jdbc/myds' " appear when I using jaas to get the DataSource“javax.naming.NameNotFoundException; 剩余名称 'env/jdbc/myds'” 当我使用 jaas 获取数据源时出现
【发布时间】:2015-03-22 00:24:28
【问题描述】:

我使用 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");

【问题讨论】:

    标签: datasource jndi jaas jetty-9


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2011-01-09
      • 1970-01-01
      • 2016-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多