正如博客/书籍中提到的(例如Mark Richards的Java Transactions Design Strategies),读取操作必须具有Propagation.SUPPORTS属性.
在一个带有Hibernate 4.1的简单Spring 3.1 MVC项目中,场景是:
当然,当Controller执行读操作的功能时,会引发异常"找不到当前线程的会话",因为没有启动事务并且没有获得会话.
基于上述配置(尽管最好是非侵入性,较少代码等),除非在使用Propagation.REQUIRED或Propagation.REQUIRES_NEW之前启动事务,否则不能使用Propagation.SUPPORTS属性.
我们如何使用Propagation.SUPPORTS进行读取操作而无需启动事务,例如之前使用Propagation.REQUIRED但仍然利用声明式事务管理的好处?
先感谢您.
编码器,这是配置:
<tx:annotation-driven transaction-manager="txManager"/>
<context:component-scan base-package="com.myapps.service.impl" />
<bean id="txManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${db.driverClassName}" />
<property name="url" value="${db.url}" />
<property name="username" value="${db.username}" />
<property name="password" value="${db.password}" />
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="mappingResources">
<list>
<value>.....</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${db.dialect}</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property> …Run Code Online (Sandbox Code Playgroud) 我在用:
我有两个JMS应用程序:
转换接收的消息时,将提取空值.
我知道这必须相当简单,但我得到空值,我没有找到一个例子来看我做错了什么.
有人可以解释一下这是如何工作的吗?
域对象
public class MyDomainObj implements Serializable {
private static final long serialVersionUID = -5411260096045103654L;
private String name;
private String msg;
public MyDomainObj() {
}
public MyDomainObj(String name, String msg) {
this.name = name;
this.msg = msg;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg …Run Code Online (Sandbox Code Playgroud) 我在用:
我正在尝试使用RedirectAttributes为控制器编写一个junit测试用例.
控制器的签名是:
@RequestMapping(method = RequestMethod.POST)
public String homePOST(@Validated({ IBasic.class }) @ModelAttribute("userCommand") User userCommand,
BindingResult result, Model model,
RedirectAttributes flashAttributes)
Run Code Online (Sandbox Code Playgroud)
JUnit测试用例是:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/root-context.xml", "/servlet-context.xml" })
public class HomeControllerTest {
@Autowired
private RequestMappingHandlerAdapter handlerAdapter;
@Autowired
private RequestMappingHandlerMapping handlerMapping;
@Test
public void testHomePOST() {
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/");
request.addParameter("username", "user1");
request.addParameter("password", "mypasswd");
MockHttpServletResponse response = new MockHttpServletResponse();
Object handler;
try {
handler = handlerMapping.getHandler(request).getHandler();
ModelAndView modelAndView = handlerAdapter.handle(request,
response, handler);
assertViewName(modelAndView, "redirect:/myview");
} catch …Run Code Online (Sandbox Code Playgroud) 要求是我必须使用正则表达式解析系统属性,以便从值中删除点.
执行示例是:mvn install -Dsomeversion = 1.3
pom.xml配置是:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>regex-property</id>
<goals>
<goal>regex-property</goal>
</goals>
<configuration>
<name>someversion.parsed</name>
<value>$\{someversion}</value>
<regex>(.*)[\._](.*)</regex>
<replacement>$1$2</replacement>
<failIfNoMatch>false</failIfNoMatch>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
根据插件的文档,在美元登录后必须有反斜杠 <value>
问题是:
<failIfNoMatch>false</failIfNoMatch>任何反馈都将受到高度赞赏
先感谢您