jetty配置JNDI


Jetty配置 JNDI的代码方式

在相应的web.xml也要加入相应的引用

	<resource-ref>
		<description>showcase Datasource</description>
		<res-ref-name>jdbc/showcase</res-ref-name>
		<res-type>javax.sql.DataSource</res-type>
		<res-auth>Container</res-auth>
	</resource-ref>



public class JettyServer {
	private static final int HTTPPORT = 80;
	private static Server server;
	private static final String CONTEXT = "/";

	public static void main(String[] args) throws Exception {

		Server server = new Server(HTTPPORT);
		WebAppContext webContext = new WebAppContext("src/main/webapp", CONTEXT);
		webContext.setClassLoader(Thread.currentThread().getContextClassLoader());
		
		ComboPooledDataSource pooledDataSource = new ComboPooledDataSource();
		pooledDataSource.setDriverClass("com.mysql.jdbc.Driver");
		pooledDataSource.setJdbcUrl("jdbc:mysql://113.108.228.101:3306/dim?useUnicode=true&characterEncoding=utf8");
		pooledDataSource.setUser("sdfsdd");
		pooledDataSource.setPassword("ssdsdasfd");
		new Resource("jdbc/showcase", pooledDataSource);
		
		server.addHandler(webContext);
		server.setStopAtShutdown(true);
		server.start();


	}

}

你可能感兴趣的:(jetty)