我是 Spring 框架的新手。使用 Spring 4.3 和 Hibernate 4 开发 Web 应用程序。
我配置了所需的bean。
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"
value="${oracle.driver-calss}" />
<property name="url" value="${oracle.Url}" />
<property name="username" value="${oracle.userName}" />
<property name="password" value="${oracle.password}" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${oracle.dialect}</prop>
<prop key="hibernate.hbm2ddl.auto">${oracle.hbm2ddl}</prop>
<prop key="hibernate.show-sql">${oracle.show-sql}</prop>
</props>
</property>
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan" value="com.wmosIIBL.model"></property>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<tx:annotation-driven />
这是我的服务类
@Service
public class ItemIBLService {
@Autowired
ItemIBLDaoImpl itemIBLDaoImpl;
@Transactional
public ItemInvnByLcn getItemIBLByDspLocn(String dspLocn) {
ItemInvnByLcn itemInvnByLcn = null;
try {
itemIBLDaoImpl.getIBLByDspLocn(dspLocn);
} catch (DataAccessException dataAccessException) {
System.out.println(dataAccessException.getMessage().toString());
}
return itemInvnByLcn;
}
}
DAO Impl 代码:我故意犯一些错误来创建异常。所以请忽略代码错误并帮助我找到如何捕获抛出的异常。
郎朗坤
相关分类