title: Spring Hibernate Lazy loading - no session
body: <p>i have a lazy loading problem at a service call or at least i thought i just have a lazy loading problem... it seems to be, that i have a session problem => the session is not available during the hole service call.</p>
  
  <p>This is my service-source:</p>
  
  
  
  <pre><code>@Service
  public class MyServiceImpl implements MyService{
  
    @Autowired
    private MyRepository myRepository;
  
    @Override
    @Transactional
    public MyDTO find(String pk){
      MyObject o = myRepository.findByPK(pk);
      o.lazyCall();//Exception, but only at server call, tests runs without any problems
    }
  }
  </code></pre>
  
  
  
  <p>My Test-Class is annotated with:</p>
  
  
  
  <pre><code>@Test
  @ContextConfiguration (locations = { "classpath:spring-test-config.xml" })
  @TransactionConfiguration (transactionManager="transactionManager", defaultRollback=true)
  @Transactional
  public class MyServiceTest
      extends AbstractTransactionalTestNGSpringContextTests{
  </code></pre>
  
  <p>
  and the test runs fine.</p>
  
  <p>But if i deploy my stuff into a jetty server, i receive this exception:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.test.product.domain.ProductBase.productComponent, could not initialize proxy - no Session
   at org.hibernate.collection.internal.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:575) ~[hibernate-core-4.3.9.Final.jar:4.3.9.Final]
   at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:214) ~[hibernate-core-4.3.9.Final.jar:4.3.9.Final]
   at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:554) ~[hibernate-core-4.3.9.Final.jar:4.3.9.Final]
   at org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:142) ~[hibernate-core-4.3.9.Final.jar:4.3.9.Final]
   at org.hibernate.collection.internal.PersistentBag.iterator(PersistentBag.java:294) ~[hibernate-core-4.3.9.Final.jar:4.3.9.Final]
   at java.util.Collections$UnmodifiableCollection$1.&lt;init&gt;(Collections.java:1039) ~[na:1.8.0_25]
   at java.util.Collections$UnmodifiableCollection.iterator(Collections.java:1038) ~[na:1.8.0_25]
   at com.test.service.MyServiceImpl.find(MyServiceImpl.java:104) ~[My.service-0.0.1-SNAPSHOT.jar:na]
   at com.test.webservice.MyServiceController.create(MyServiceController.java:44) ~[classes/:na]
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_25]
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_25]
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_25]
   at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_25]
   at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) ~[spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]
   at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) ~[spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]
   at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) ~[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]
   at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:776) ~[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]
   at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705) ~[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]
   at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]
   at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) ~[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]
   at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) ~[spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]
   at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]
   at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:707) [javax.servlet-api-3.1.0.jar:3.1.0]
   at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842) [spring-webmvc-4.1.6.RELEASE.jar:4.1.6.RELEASE]
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [javax.servlet-api-3.1.0.jar:3.1.0]
   at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:816) [jetty-servlet-9.3.0.RC1.jar:9.3.0.RC1]
   at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1684) [jetty-servlet-9.3.0.RC1.jar:9.3.0.RC1]
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:316) [spring-security-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
   at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:126) [spring-security-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
   at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:90) [spring-security-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) [spring-security-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
   at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:114) [spring-security-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) [spring-security-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
   at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:122) [spring-security-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) [spring-security-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
   at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111) [spring-security-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) [spring-security-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
   at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:168) [spring-security-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) [spring-security-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
   at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:48) [spring-security-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) [spring-security-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
   at org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter.doFilter(DefaultLoginPageGeneratingFilter.java:162) [spring-security-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) [spring-security-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
   at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:205) [spring-security-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) [spring-security-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
   at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:120) [spring-security-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) [spring-security-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
   at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:64) [spring-security-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) [spring-security-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
   at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:53) [spring-security-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
   at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) [spring-security-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
   at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:91) [spring-security-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
   at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330) [spring-security-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
   at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:213) [spring-security-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
   at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:176) [spring-security-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
   at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344) [spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]
   at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261) [spring-web-4.1.6.RELEASE.jar:4.1.6.RELEASE]
   at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1667) [jetty-servlet-9.3.0.RC1.jar:9.3.0.RC1]
   at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:581) [jetty-servlet-9.3.0.RC1.jar:9.3.0.RC1]
   at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) [jetty-server-9.3.0.RC1.jar:9.3.0.RC1]
   at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548) [jetty-security-9.3.0.RC1.jar:9.3.0.RC1]
   at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226) [jetty-server-9.3.0.RC1.jar:9.3.0.RC1]
   at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1121) [jetty-server-9.3.0.RC1.jar:9.3.0.RC1]
   at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:511) [jetty-servlet-9.3.0.RC1.jar:9.3.0.RC1]
   at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185) [jetty-server-9.3.0.RC1.jar:9.3.0.RC1]
   at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1055) [jetty-server-9.3.0.RC1.jar:9.3.0.RC1]
   at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) [jetty-server-9.3.0.RC1.jar:9.3.0.RC1]
   at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:213) [jetty-server-9.3.0.RC1.jar:9.3.0.RC1]
   at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:109) [jetty-server-9.3.0.RC1.jar:9.3.0.RC1]
   at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:118) [jetty-server-9.3.0.RC1.jar:9.3.0.RC1]
   at org.eclipse.jetty.server.Server.handle(Server.java:515) [jetty-server-9.3.0.RC1.jar:9.3.0.RC1]
   at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:291) [jetty-server-9.3.0.RC1.jar:9.3.0.RC1]
   at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:242) [jetty-server-9.3.0.RC1.jar:9.3.0.RC1]
   at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:238) [jetty-io-9.3.0.RC1.jar:9.3.0.RC1]
   at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95) [jetty-io-9.3.0.RC1.jar:9.3.0.RC1]
   at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:57) [jetty-io-9.3.0.RC1.jar:9.3.0.RC1]
   at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:191) [jetty-util-9.3.0.RC1.jar:9.3.0.RC1]
   at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:126) [jetty-util-9.3.0.RC1.jar:9.3.0.RC1]
   at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654) [jetty-util-9.3.0.RC1.jar:9.3.0.RC1]
   at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572) [jetty-util-9.3.0.RC1.jar:9.3.0.RC1]
   at java.lang.Thread.run(Thread.java:745) [na:1.8.0_25]
  2015-07-15 00:00:28,383 | DEBUG | qtp1971855969-26 | o.s.s.w.c.Sec</code></pre>
  </div>
  </div>
  </p>
  
  <p>And finally my server datasource / tx configuration looks like this:</p>
  
  
  
  <pre><code>&lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;property name="driverClassName" value="${db.driver}" /&gt;
          &lt;property name="url" value="${db.url}" /&gt;
          &lt;property name="username" value="${db.username}" /&gt;
          &lt;property name="password" value="${db.password}" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
  
          &lt;property name="dataSource" ref="dataSource" /&gt;
  
          &lt;property name="packagesToScan" &gt;
              &lt;list&gt;
                  &lt;value&gt;com.test&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
  
          &lt;property name="jpaVendorAdapter"&gt;
              &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
                  &lt;property name="showSql" value="true" /&gt;
                  &lt;property name="generateDdl" value="true" /&gt;
              &lt;/bean&gt;
          &lt;/property&gt;
  
      &lt;/bean&gt;
  
      &lt;!-- Transaction Manager configuration --&gt;
      &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;
  
      &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" &gt;
          &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
      &lt;/bean&gt;
  </code></pre>
  
  
  
  <p>So what's the difference? Why is the behavior between the test and the server different? Why i don't have a database session in my servicemethod, but when i load something from the database i have a session? I read something about OpenSessionInViewFilter but this seems to be a solution for a front end app => but i want to implement a rest-server, which is called by a frontend.</p>
  
  <p>Any ideas? Please help. </p>
  
  <p>KR</p>
  
  <p>--- update ---
  Complete config files:</p>
  
  <p>root-context.xml:
  </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:jpa="http://www.springframework.org/schema/data/jpa"
      xmlns:context="http://www.springframework.org/schema/context"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xmlns:jms="http://www.springframework.org/schema/jms"
      xmlns:amq="http://activemq.apache.org/schema/core"
      xmlns:util="http://www.springframework.org/schema/util"
      xsi:schemaLocation="
          http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context-3.2.xsd
          http://www.springframework.org/schema/data/jpa
          http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
          http://www.springframework.org/schema/util
          http://www.springframework.org/schema/util/spring-util-3.0.xsd
          http://www.springframework.org/schema/jms 
          http://www.springframework.org/schema/jms/spring-jms.xsd
          http://activemq.apache.org/schema/core 
          http://activemq.apache.org/schema/core/activemq-core.xsd
          http://www.springframework.org/schema/tx
          http://www.springframework.org/schema/tx/spring-tx.xsd"
      default-autowire="byName"&gt;
  
      &lt;!-- Root Context: defines shared resources visible to all other web components --&gt;
  
      &lt;!-- only components from this package can be wired by spring --&gt; 
      &lt;context:component-scan base-package="com.test.product.*" /&gt;
      &lt;context:component-scan base-package="com.test.person.*" /&gt;
  
      &lt;!-- Directory to scan for repository classes --&gt;
      &lt;jpa:repositories base-package="com.test.*.domain.repository" /&gt;
  
      &lt;!-- jdbc.properties =&gt; used to put db-connection data to an own property-file --&gt;
      &lt;bean id="domainPropertyConfigurer"
          class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
          &lt;property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /&gt;
          &lt;property name="locations"&gt;
              &lt;list&gt;
                  &lt;value&gt;/WEB-INF/jdbc.properties&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
      &lt;!--  Datasource configuration - which database we use, look for jdbc.properties to set this data --&gt;
      &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;property name="driverClassName" value="${db.driver}" /&gt;
          &lt;property name="url" value="${db.url}" /&gt;
          &lt;property name="username" value="${db.username}" /&gt;
          &lt;property name="password" value="${db.password}" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
  
          &lt;property name="dataSource" ref="dataSource" /&gt;
  
          &lt;property name="packagesToScan" &gt;
              &lt;list&gt;
                  &lt;value&gt;com.test.product.domain&lt;/value&gt;
                  &lt;value&gt;com.test.person.domain&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
  
          &lt;property name="jpaVendorAdapter"&gt;
              &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
                  &lt;property name="showSql" value="true" /&gt;
                  &lt;property name="generateDdl" value="true" /&gt;
              &lt;/bean&gt;
          &lt;/property&gt;
  
      &lt;/bean&gt;
  
      &lt;!-- Transaction Manager configuration --&gt;
      &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;
  
      &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager" &gt;
          &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
      &lt;/bean&gt;
  
      &lt;!-- Couch DB Configuration --&gt;
  
      &lt;!-- production and configuration or if you want to do a test to a real couch db (for example at continues integration) --&gt;
  
      &lt;util:properties id="couchdbProperties" location="/WEB-INF/couchdb.properties"/&gt;
  
      &lt;bean id="documentArchiveDatabase" class="org.ektorp.impl.StdCouchDbConnector"&gt;
          &lt;constructor-arg value="documentArchive" /&gt;
          &lt;constructor-arg&gt;
              &lt;bean id="couchDbInstance" class="org.ektorp.impl.StdCouchDbInstance"&gt;
                  &lt;constructor-arg&gt;
                      &lt;bean class="org.ektorp.spring.HttpClientFactoryBean" /&gt;
                  &lt;/constructor-arg&gt;
              &lt;/bean&gt;
          &lt;/constructor-arg&gt;
      &lt;/bean&gt;
  
      &lt;!-- START JMS Config --&gt;
  
      &lt;jms:annotation-driven/&gt;
  
      &lt;!-- Possible productive configuration --&gt;
  
  
      &lt;amq:broker id="broker" useJmx="false" persistent="false" &gt;
          &lt;amq:transportConnectors&gt;
              &lt;amq:transportConnector uri="tcp://localhost:61616"/&gt;
          &lt;/amq:transportConnectors&gt;
      &lt;/amq:broker&gt;
  
      &lt;bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"&gt; 
          &lt;property name="brokerURL" value="tcp://localhost:61616"/&gt;
      &lt;/bean&gt; 
  
      &lt;bean id="cachingConnectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory"&gt;
          &lt;property name="targetConnectionFactory" ref="connectionFactory"/&gt;
      &lt;/bean&gt; 
  
      &lt;bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"&gt;
          &lt;property name="connectionFactory" ref="cachingConnectionFactory"/&gt;
      &lt;/bean&gt;
  
      &lt;bean id = "destinationResolver" class = "org.springframework.jms.support.destination.DynamicDestinationResolver"&gt;&lt;/bean&gt;
  
      &lt;bean id="jmsListenerContainerFactory" class="org.springframework.jms.config.DefaultJmsListenerContainerFactory"&gt;
          &lt;property name="connectionFactory" ref="connectionFactory"/&gt;
          &lt;property name="destinationResolver" ref="destinationResolver"/&gt;
          &lt;property name="concurrency" value="1-10"/&gt;
      &lt;/bean&gt;
  
      &lt;!-- END JMS Config --&gt;
  
  
  &lt;/beans&gt;
  </code></pre>
  
  
  
  <p>Spring-Security.xml:
  </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans:beans xmlns="http://www.springframework.org/schema/security"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
      xmlns:sec="http://www.springframework.org/schema/security"
      xsi:schemaLocation="
        http://www.springframework.org/schema/security
        http://www.springframework.org/schema/security/spring-security-4.0.xsd
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.0.xsd"&gt;
  
      &lt;http entry-point-ref="restAuthenticationEntryPoint"&gt;
          &lt;intercept-url pattern="/rest/**" access="hasRole('ROLE_USER')" /&gt;
  
          &lt;form-login authentication-success-handler-ref="mySuccessHandler"
              authentication-failure-handler-ref="myFailureHandler" /&gt;
          &lt;logout /&gt;
          &lt;csrf disabled="true"/&gt;
      &lt;/http&gt;
  
      &lt;beans:bean id="restAuthenticationEntryPoint" class="com.test.webservice.security.RestAuthenticationEntryPoint" /&gt;
  
      &lt;beans:bean id="mySuccessHandler"
          class="com.test.webservice.security.RestAuthenticationSuccessHandler" /&gt;
      &lt;beans:bean id="myFailureHandler"
          class="org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler" /&gt;
  
      &lt;authentication-manager alias="authenticationManager"&gt;
          &lt;authentication-provider&gt;
              &lt;user-service&gt;
                  &lt;user name="temporary" password="temporary" authorities="ROLE_ADMIN" /&gt;
                  &lt;user name="user" password="user" authorities="ROLE_USER" /&gt;
              &lt;/user-service&gt;
          &lt;/authentication-provider&gt;
      &lt;/authentication-manager&gt;
  
  &lt;/beans:beans&gt;
  </code></pre>
  
  
  
  <p>Servlet-context.xml</p>
  
  
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans:beans xmlns="http://www.springframework.org/schema/mvc"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xmlns:beans="http://www.springframework.org/schema/beans"
      xmlns:context="http://www.springframework.org/schema/context"
      xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"&gt;
  
      &lt;!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure --&gt;
  
       &lt;!-- Configure to plugin JSON as request and response in method handler --&gt;
      &lt;annotation-driven&gt;
          &lt;message-converters&gt;
               &lt;beans:bean class="org.springframework.http.converter.StringHttpMessageConverter"&gt;
               &lt;/beans:bean&gt;
               &lt;beans:bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"&gt;
                  &lt;beans:property name="objectMapper"&gt;
                      &lt;beans:bean class="com.test.webservice.MyObjectMapper" /&gt;
                  &lt;/beans:property&gt;
              &lt;/beans:bean&gt;
          &lt;/message-converters&gt;
      &lt;/annotation-driven&gt;
  
      &lt;!-- only components from this package can be wired by spring --&gt; 
      &lt;context:component-scan base-package="com.test.product.*" /&gt;
      &lt;context:component-scan base-package="com.test.person.*" /&gt;
  
  
  &lt;/beans:beans&gt;
  </code></pre>
  
  
  
  <p>Web.xml</p>
  
  
  
  <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
  &lt;web-app 
     xmlns="http://java.sun.com/xml/ns/javaee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
     version="2.5"&gt; 
  
     &lt;!-- The definition of the Root Spring Container shared by all Servlets and Filters --&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/spring/root-context.xml, /WEB-INF/spring/spring-security.xml&lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;!-- Creates the Spring Container shared by all Servlets and Filters --&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  
      &lt;!-- Processes application requests --&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
              &lt;param-value&gt;/WEB-INF/spring/appServlet/servlet-context.xml&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      &lt;!-- Security Stuff --&gt;
      &lt;filter&gt;
          &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
          &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
      &lt;/filter&gt;
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  
  
  <p>jdbc.properties</p>
  
  
  
  <pre><code>db.driver=org.h2.Driver
  db.url=jdbc:h2:mem:test;DB_CLOSE_DELAY=-1
  db.username=sa
  db.password=
  
  db.memurl=jdbc:h2:mem:test
  </code></pre>