jetty 配置数据源以及应用

1、pom.xml:


    <dependency>
       <groupId>org.springframework</groupId>
       <artifactId>spring-jdbc</artifactId>
       <version>${spring.version}</version>
    </dependency>

    <dependency>
         <groupId>mysql</groupId>
         <artifactId>mysql-connector-java</artifactId>
         <version>5.1.14</version>
     </dependency>


     <plugin>
            <groupId>org.eclipse.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>9.2.19.v20160908</version>
            <configuration>
                 <jettyXml>${basedir}/jetty.xml</jettyXml>
                 <webApp>
                     <jettyEnvXml>${basedir}/jetty-env.xml</jettyEnvXml>     <!--这个一定要有,这里面配的是数据源-->
                 </webApp>

                 <httpConnector>
                     <port>9080</port>
                 </httpConnector>
            </configuration>
        </plugin>


2、jetty.xml:


<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">


<!-- =============================================================== -->
<!-- Configure the Jetty Server -->
<!-- -->
<!-- Documentation of this file format can be found at: -->
<!-- http://wiki.eclipse.org/Jetty/Reference/jetty.xml_syntax -->
<!-- -->
<!-- Additional configuration files are available in $JETTY_HOME/etc -->
<!-- and can be mixed in. For example: -->
<!-- java -jar start.jar etc/jetty-ssl.xml -->
<!-- -->
<!-- See start.ini file for the default configuraton files -->
<!-- =============================================================== -->




<Configure id="Server" class="org.eclipse.jetty.server.Server">
    <!-- =========================================================== -->
    <!-- Set handler Collection Structure -->
    <!-- =========================================================== -->
    <Set name="handler">
        <New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
            <Set name="handlers">
                <Array type="org.eclipse.jetty.server.Handler">
                    <Item>
                        <New id="Contexts" class="org.eclipse.jetty.server.handler.ContextHandlerCollection"/>
                    </Item>
                    <Item>
                        <New id="DefaultHandler" class="org.eclipse.jetty.server.handler.DefaultHandler"/>
                    </Item>
                </Array>
            </Set>
        </New>
    </Set>
</Configure>


3、jetty-env.xml:

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">


<Configure class="org.eclipse.jetty.webapp.WebAppContext">
    <New id="semanticDB" class="org.eclipse.jetty.plus.jndi.Resource">
        <Arg>java:jboss/jdbc/ps_admin</Arg>    <!--这个是连接下面的数据源的标识-->
        <Arg>
            <New class="com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource">
                <Set name="Url">jdbc:mysql://101.27.19.191:3306/ps_admin</Set>
                <Set name="User">***</Set>
                <Set name="Password">****</Set>
            </New>
        </Arg>
    </New>
</Configure>


4、web.xml:

<init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/config/springMVC-servlet.xml 
             /WEB-INF/config/authority_applicationContext.xml</param-value>
        </init-param>


5、authority_applicationContext.xml:


<jee:jndi-lookup id="csdataSource" jndi-name="java:jboss/jdbc/ps_admin" />  <!--对应数据源配置中的标识-->
    <bean id="urlJdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="csdataSource" />
    </bean>


6、应用:

   @Autowired
    private JdbcTemplate jdbcTemplate;

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值