上篇整合了jndi+tomcat,这篇继续加入spring和hibernate
直接看配置文件
修改tomcat/conf/context.xml(这里是全局jndi配置)
在Context标签里添加:
web.xml中加入
applicationContext.xml
其余配置均相同,代码也一样。
直接看配置文件
修改tomcat/conf/context.xml(这里是全局jndi配置)
在Context标签里添加:
<Resource name="jdbc/mysql" auth="Container"
type="javax.sql.DataSource" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/fly"
username="root"
password="1234"
maxActive="20"
maxIdle="10"/>
web.xml中加入
<resource-ref>
<description>DB Connection</description>
<res-ref-name>jdbc/mysql</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
applicationContext.xml
<jee:jndi-lookup id="myDataSource" jndi-name="java:comp/env/jdbc/mysql" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="annotatedClasses">
<list>
<value>com.flyhigher.messy.domain.User</value>
</list>
</property>
<property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.show_sql=true
</value>
</property>
</bean>
其余配置均相同,代码也一样。