【问题标题】:Configuring DataSources with IDEA IntelliJ Jetty Plugin (jetty-env.xml)使用 IDEA IntelliJ Jetty 插件 (jetty-env.xml) 配置数据源
【发布时间】:2012-11-20 16:07:02
【问题描述】:

我正在尝试开始使用 IDEA IntelliJ Jetty 插件。在我们的应用程序中,我们使用 JNDI 数据源来访问实际的数据库。

因此,为了开发,我们生成一个 jetty-env.xml 并在开发部署期间将其包含在 WEB-INF 目录中:

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
<Configure class="org.mortbay.jetty.webapp.WebAppContext">
  <!-- Add an JNDI resource -->
  <New class="org.mortbay.jetty.plus.naming.Resource">
        <Arg>datasource_pbv</Arg>
        <Arg>
            <New class="org.apache.commons.dbcp.BasicDataSource">
                <Set name="DriverClassName">oracle.jdbc.driver.OracleDriver</Set>
                <Set name="Url">jdbc:oracle:thin:@dbserver:1521:DATABASE</Set>
                <Set name="Username">user</Set>
                <Set name="Password">pass</Set>
            </New>
        </Arg>
    </New>
</Configure>

我以这种方式在 jetty.xml 中重新配置了 Jetty WebAppDeployer,因此它使用了 org.mortbay.jetty.plus.webapp.EnvConfiguration 读取并处理 jetty-env.xml:

<Configure id="Server" class="org.mortbay.jetty.Server">  
    ...
    <Array id="plusConfig" type="java.lang.String">
      <Item>org.mortbay.jetty.webapp.WebInfConfiguration</Item>
      <Item>org.mortbay.jetty.plus.webapp.EnvConfiguration</Item>
      <Item>org.mortbay.jetty.plus.webapp.Configuration</Item>
      <Item>org.mortbay.jetty.webapp.JettyWebXmlConfiguration</Item>
      <Item>org.mortbay.jetty.webapp.TagLibConfiguration</Item>
    </Array>
    ...
    <Call name="addLifeCycle">
      <Arg>
        <New class="org.mortbay.jetty.deployer.WebAppDeployer">
            ...              
            <Set name="configurationClasses"><Ref id="plusConfig"/></Set>
        </New>
      </Arg>
    </Call>
    ...
</Configure>    

很遗憾,这不适用于 IDEA Jetty 插件。 IDEA Jetty 插件会生成一个 context-config.xml 和一个后续的 war-exploded.xml,它不会添加 EnvConfiguration。 因此使用 Jetty IDEA 插件部署时会忽略 jetty-env.xml。

在使用 IDEA Jetty 插件部署时,我如何才能使这项工作或其他方式提供自定义 JNDI 条目?

【问题讨论】:

    标签: intellij-idea jetty jndi


    【解决方案1】:

    我还没有检查过自己,但是由于 IDEA Jetty 集成依赖于ContextDeployer,因此以下应该可以工作(如果添加到jetty.xml):

    <Call name="addLifeCycle">
      <Arg>
        <New class="org.mortbay.jetty.deployer.ContextDeployer">
            ...              
            <Set name="configurationClasses"><Ref id="plusConfig"/></Set>
        </New>
      </Arg>
    </Call>
    

    【讨论】:

      猜你喜欢
      • 2012-07-04
      • 1970-01-01
      • 2011-05-01
      • 2023-01-25
      • 2013-01-08
      • 2011-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多