0

我需要一个弹簧数据源,例如:

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">                  
  <property name="driverClassName" value="<driver>"/>                
  <property name="url" value="<url>" />                
  <property name="username" value="<user>" />     
  <property name="password" value="<pass>" />
</bean> 

我需要从persistence.xml 中获取驱动程序、url、用户、传递。

坦克很多!

4

2 回答 2

0

Here is my snippet for doign the same, you will obviously have to use your BasicDataSource instead of the ComboPooledDataSource I use. But they are pretty much the same, replace getDriverClass() with driverClassName, apparently.

@Autowired
private ComboPooledDataSource dataSource;

public String myMethod() {
  return dataSource.getDriverClass());
}
于 2012-02-13T13:35:38.293 回答
0

您想打印它,还是在您的应用程序中使用它来连接 dB?

如果是后一种情况,则为 sessionFactory 创建一个 bean,将 hibernateProperties 设置为相同的位置,您也可以在其中注入数据源。

在 java 代码中,自动装配 sessionFactory 对象(或使用 setter 方法设置它)并为此调用 getCurrentSession 方法。

要获取各种属性,请使用链式 getter 方法返回数据源并提取所有详细信息。

如果您遇到任何问题或需要更多详细信息,请告诉我。

于 2012-02-13T13:39:11.833 回答