Jetty 7:为Start.java配置JNDI

继Wicket 1.5领先后,我将一个项目从Jetty 6.1.25转换为7.5.0.v20110901.我现有的Start. java包含以下设置,我用它来配置JNDI:

EnvConfiguration envConfiguration = new EnvConfiguration();
    URL url = new File("src/main/webapp/WEB-INF/jetty-env.xml").toURI().toURL();
    envConfiguration.setJettyEnvXml(url);

    bb.setConfigurations(new Configuration[]{new WebInfConfiguration(),
                         envConfiguration,
                         new org.mortbay.jetty.plus.webapp.Configuration(), new JettyWebXmlConfiguration(),
                         new TagLibConfiguration()});

然后我的jetty-env.xml有以下内容:

<Configure class="org.mortbay.jetty.webapp.WebAppContext">

    <New class="org.mortbay.jetty.plus.naming.Resource">
        <Arg>jdbc/myapp</Arg>
        <Arg>
            <New class="org.springframework.jdbc.datasource.DriverManagerDataSource">
                <Set name="driverClassName">com.mysql.jdbc.Driver</Set>
                <Set name="url">jdbc:mysql://localhost/myapp?characterEncoding=utf8</Set>
                <Set name="username">username</Set>
                <Set name="password">password</Set>
            </New>
        </Arg>
    </New>

</Configure>

这在Jetty 6中运行得很好,但在7中,org.mortbay.jetty.plus.webapp.Configuration似乎不存在(或者我可能错过了一个Jar).

有人可以给我一些关于如何使用Jetty 7配置JNDI的指导吗?

将以下内容放入src / test / jetty / jetty-env.xml:

<Configure id="wac" class="org.eclipse.jetty.webapp.WebAppContext">
    <New class="org.eclipse.jetty.plus.jndi.EnvEntry">
    <Arg>jdbc/mydatasource</Arg>
    <Arg>
        <New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
            <Set name="Url">jdbc:mysql://localhost/mydatabase?characterEncoding=utf8</Set>
            <Set name="User">username</Set>
            <Set name="Password">password</Set>
        </New>
    </Arg>
    </New>
</Configure>

然后修改Start.java以定义以下属性:

System.setProperty("java.naming.factory.url.pkgs", "org.eclipse.jetty.jndi");
System.setProperty("java.naming.factory.initial", "org.eclipse.jetty.jndi.InitialContextFactory");

并将以下配置添加到WebAppContext:

EnvConfiguration envConfiguration = new EnvConfiguration();
URL url = new File("src/test/jetty/jetty-env.xml").toURI().toURL();
envConfiguration.setJettyEnvXml(url);

bb.setConfigurations(new Configuration[]{ new WebInfConfiguration(), envConfiguration, new WebXmlConfiguration() });

关于我blog的全部细节.

相关文章
相关标签/搜索