jetty 配置数据源以及应用
2017-12-21 17:40
387 查看
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.xm
4000
l:
<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;
<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.xm
4000
l:
<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;
相关文章推荐
- jetty配置数据源以及应用2
- 本地配置JNDI数据源(可供以jetty启动的web应用通过查询JNDI调用)
- Jetty插件,运行web应用配置
- jetty-7.0.0pre3在MyEclipse 7.0M1 Eclipse3.4中应用配置
- redis在java项目中的配置以及应用
- centos 5.8 x64Jetty的安装以及项目部署配置
- centos 5.8 x64Jetty的安装以及项目部署配置
- ThreadPoolExecutor策略配置以及应用场景
- 应用在tomcat上的部署以及将免安装的tomcat配置成服务自启动
- log4j2相关配置说明以及${sys:catalina.home}应用
- memcached在Java中的应用以及magent的配置-每天进步一点点
- LINUX目录和文件各自的权限说明,以及目录和文件权限之间的关系(应用:配置linux下上传图片的存储目录)
- SSD配置、训练、测试以及应用到自己的数据集
- linux 下安装配置jboss as7以及部署应用
- Quartz集群原理以及配置应用的方法详解
- Linux环境thinkphp配置以及数据源驱动修改
- 详解SpringBoot初始教程之Tomcat、Https配置以及Jetty优化
- 从Weblogic迁移至Apusic以及配置默认应用
- linux 下安装配置jboss as7以及部署应用
- 详细介绍在tomcat中配置数据源以及数据源的原理