如何将另一个 Java 项目中的数据库类(作为对动态 Web 应用程序的依赖项添加)添加为托管属性?
import java.sql.Connection;
import org.h2.jdbcx.JdbcConnectionPool;
import java.sql.SQLException;
public class Database
{
private JdbcConnectionPool poolMgr;
public Database(String path, String user, String password, int connectionPoolSize) throws SQLException
{
// Creates connection pool
poolMgr = JdbcConnectionPool.create(path, user, password);
poolMgr.setMaxConnections(connectionPoolSize);
}
public Connection getConnection() throws SQLException
{
return poolMgr.getConnection();
}
}
package com.project1.bean;
import com.project2.db.Database;
@ManagedBean
@RequestScoped
public class InputBean implements Serializable
{
@ManagedProperty("#{database}")
private Database database;
//getters and setters
}