Pessoal to utilizando o spring, hibernate- JPA, tomcat…
como faço pra as conexões com o banco via JNDI, abrir e fechar a cargo do Spring…
pra teste por enquanto a conexão com o banco ta assim no xml do spring:
[code]
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost/teste"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
<property name="initialSize" value="5"/>
<property name="maxActive" value="10"/>
</bean> [/code]
to tendo um problema de performance durante alguns teste e creio que seja pela conexão com o banco…
vlw
Cara, eu recomendaria que você deixasse o pool de conexões a cargo do tomcat:
No arquivo server.xml do tomcat:
<Resource name=“jdbc/myoracle” auth=“Container”
type=“javax.sql.DataSource” driverClassName=“oracle.jdbc.OracleDriver”
url=“jdbc:oracle:thin:@127.0.0.1 :1521:mysid”
username=“scott” password=“tiger” maxActive=“20” maxIdle=“10”
maxWait="-1"/>
No seu web.xml
<resource-ref>
<description>Oracle Datasource example</description>
<res-ref-name>jdbc/myoracle</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
Para obter o datasource:
Context initContext = new InitialContext();
Context envContext = (Context)initContext.lookup(“java:/comp/env”);
DataSource ds = (DataSource)envContext.lookup(“jdbc/myoracle”);
Connection conn = ds.getConnection();
//etc.
no spring (datasource)
<bean id=“dataSource”
class=“org.springframework.jndi.JndiObjectFactoryBean”>
<property name=“jndiName”>
<value>java:comp/env/jdbc/myoracle</value>
</property>
</bean>
no spring (hibernate)
<bean id=“sessionFactory”
class=“org.springframework.orm.hibernate.
LocalSessionFactoryBean”>
<property name=“dataSource”><ref bean=“dataSource”/></property>
<property name=“hibernateProperties”>
<props>
<prop key=“hibernate.dialect”>
…
</prop>
<prop key=“hibernate.hbm2ddl.auto”>update</prop>
</props>
</property>
</bean>
Espero ter ajudado no que precisava…
Qualquer dúvida estamos aí…
Mais informações:
http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html
http://www.javafree.org/content/view.jf?idContent=46
Since the first version of this article was published in October, 2003, the Spring Framework has steadily grown in popularity. It has progressed through version 1.0 final to the present 1.2, and has been adopted in a wide range of industries and...
vlw a todos isso que eu precisava…