我试图基于GenericDao制作web服务.我有Person Entity,我试图为GenericDao扩展的Entity制作dao.但是@Transactional注释不会打开事务:TransactionSynchronizationManager.isActualTransactionActive() = false
我找不到我想念的地方@Transactional.我试图@Transactional几乎随处可见.感觉就像注释不是从GenericDao继承的..
春天-config.xml中
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://127.0.0.1:5432/test" />
<property name="username" value="postgres" />
<property name="password" value="postgress" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="annotatedClasses">
<list>
<value>org.entity.nci.person.Person</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop
key="hibernate.dialect">org.hibernate.dialect.HSQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="packagesToScan" value="com.byteslounge.spring.tx.model" />
</bean>
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager" …Run Code Online (Sandbox Code Playgroud) 我有一个带有标题的 CSV 文件,例如:-
标题、项目 ID、摘要、优先级
1,1,测试总结,高
现在我想获取在 CSV 文件中传递的标题列表。
笔记:每次传递的标头都会不同。
提前致谢
在我的spring-jdbc项目中,我有一个类DBStuff,我用它连接到db并进行简单的数据库操作.这是一个Web项目,有用户,所以我自然会使用会话机制.当我需要在DBStuff类中检索请求数据时,我使用下面这行代码:
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
Run Code Online (Sandbox Code Playgroud)
但是,没有解释,如果RequestContextHolder是线程安全的.即使是春天的官方论坛也没有答案.由于使用servlet,我需要为用户提供线程安全的特性.
根据定义RequestContextHolder,定义为"以线程绑定RequestAttributes对象的形式公开Web请求的Holder类".但我不确定"线程绑定"是否代表线程安全.