Tag Archives: spring

Spring with multiple transaction managers

zt4PX
Here is repost of http://stackoverflow.com/questions/4423125/spring-is-it-possible-to-use-multiple-transaction-managers-in-the-same-applica question.

Here is applicationContext.xml config part:

<bean id="transactionManager1" class="org.springframework.orm.jpa.JpaTransactionManager"> 
  <property name="entityManagerFactory" ref="entityManagerFactory1" /> 
  <qualifier value="account"/> 
</bean>

<bean id="transactionManager2" class="org.springframework.orm.jpa.JpaTransactionManager">
  <property name="entityManagerFactory" ref="entityManagerFactory2" /> 
  <qualifier value="businessData"/> 
</bean>

and code using:

public class TransactionalService {

    @Transactional("account")
    public void setSomethingInAccount() { ... }

    @Transactional("businessData")
    public void doSomethingInBusinessData() { ... }
}

So, as you see we can simply use several connections with transaction management in Spring application.

See also,
http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/transaction.html#tx-multiple-tx-mgrs-with-attransactional
Enjoy!

Set charset in Spring MVC


To set up encoding for site, you can use CharacterEncodingFilter in web.xml like this:


 encodingFilter
 org.springframework.web.filter.CharacterEncodingFilter
 
  encoding  
  UTF-8  
   
  
 forceEncoding  
 true  
   
  

  
encodingFilter  
/*  

Also http://stackoverflow.com/questions/138948/how-to-get-utf-8-working-in-java-webapps

Get application context in Spring Web project

To get access to appContext, just extends your class from WebApplicationObjectSupport and use:

ISome some = null;
try
{
some= (ISome)getApplicationContext().getBean("Some");
}
catch (Exception e)
{
logger.debug("Some is not defined in AppContext.");
}

List in Spring

Often need for simple list in app context.





	    h1
	    h2
	    h3
	

Also, may be useful http://www.mkyong.com/spring/spring-collections-list-set-map-and-properties-example/