title: LazyInitializationException: could not initialize proxy - no Session
body: <p>I use <code>spring-data-jpa</code> with <code>spring-boot(v2.0.0.RELEASE)</code>, I just wrote a CRUD demo on MySQL, but an exception occurs during runtime, source code as follows:  </p>
  
  <p><strong>Source code</strong>  </p>
  
  <p><em>User.java</em></p>
  
  <pre><code>@Entity
  public class User implements Serializable {
      private static final long serialVersionUID = 1L;
  
      @Id
      private Integer id;
      private String username;
      private String password;
  
      ...getter&amp;setter
  } 
  </code></pre>
  
  <p><em>UserRepository.java</em> </p>
  
  <pre><code>public interface UserRepository extends JpaRepository&lt;User, Integer&gt; {
  
  }
  </code></pre>
  
  <p><em>UserServiceTest.java</em>  </p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @SpringBootTest
  public class UserServiceTest {
  
      @Autowired
      private UserRepository userRepository;
  
      @Test
      public void getUserById() throws Exception{
          userRepository.getOne(1);
      }
  
  }
  </code></pre>
  
  <p><strong>application.yml</strong>  </p>
  
  <pre><code>spring:
    datasource:
      username: ***
      password: ***
      driver-class-name: com.mysql.jdbc.Driver
      url: ********
    thymeleaf:
      cache: false
    jpa:
      show-sql: true
      hibernate:
        ddl-auto: update
  </code></pre>
  
  <p><strong>Exception details</strong></p>
  
  <pre><code>org.hibernate.LazyInitializationException: could not initialize proxy - no Session
  
  at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:155)
  at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:268)
  at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:73)
  at cn.shuaijunlan.sdnsecuritysystem.domain.po.User_$$_jvstc90_0.getUsername(User_$$_jvstc90_0.java)
  at cn.shuaijunlan.sdnsecuritysystem.service.UserServiceTest.getUserById(UserServiceTest.java:33)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:498)
  at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
  at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
  at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
  at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
  </code></pre>
  
  <blockquote>
    <p>I try to another method <code>userRepository.findOne(1)</code>, it can run successfully.</p>
  </blockquote>