我的服务器启动没有任何错误。当我通过id请求获取用户时,我没有得到结果。我的数据库凭据是正确的,我已将show_sql设置为true。我仍然没有看到对DB的任何调用。 我的数据库是否已连接?
修改
如何测试连接?
配置:
dao.xml中的:
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="classpath:application.properties" />
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.url}" p:username="${jdbc.username}"
p:password="${jdbc.password}" />
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
</props>
</property>
</bean>
<tx:annotation-driven />
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
在userdaoImpl.java
@Repository
public class UserDaoImpl extends AbstractDao<Long, User> implements UserDao {
@Override
public User getUser(String id) {
Criteria criteria = createEntityCriteria();
criteria.add(Restrictions.eq("userId", id));
return (User) criteria.uniqueResult();
}