Guest User

Untitled

a guest
Apr 16th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. @GetMapping(value = "{id}", produces = MediaType.APPLICATION_JSON_VALUE)
  2. public ResponseEntity<MyObject> getDataById(@PathVariable(value = "id") Integer id)
  3. {
  4. MyObject data = myService.findOneById(String.valueOf(id));
  5. return Optional.ofNullable(data)
  6. .map(mData -> new ResponseEntity<>(mData, HttpStatus.OK))
  7. .orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));
  8. }
  9.  
  10. @Cacheable(value = "mydata", key = "#id")
  11. public MyObject findOneById(String id) {
  12. return myRepository.getOne(Integer.valueOf(id));
  13. }
  14.  
  15. spring:
  16. application:
  17. name: Spring Boot Caching With Redis
  18. datasource:
  19. driver-class-name: com.mysql.jdbc.Driver
  20. url: jdbc:mysql://localhost/redis?useUnicode=true&characterEncoding=utf8&useSSL=false
  21. name:
  22. username: root
  23. password: root
  24. hikari:
  25. data-source-properties:
  26. cachePrepStmts: true
  27. prepStmtCacheSize: 250
  28. prepStmtCacheSqlLimit: 2048
  29. useServerPrepStmts: true
  30. jpa:
  31. database-platform: org.hibernate.dialect.MySQLInnoDBDialect
  32. database: MYSQL
  33. show_sql: false
  34. properties:
  35. hibernate.cache.use_second_level_cache: false
  36. hibernate.cache.use_query_cache: false
  37. hibernate.generate_statistics: true
  38. jackson:
  39. serialization:
  40. write_dates_as_timestamps: false
  41. cache:
  42. type: redis
  43.  
  44. liquibase:
  45. change-log: classpath:liquibase/master.xml
  46.  
  47. server:
  48. port: 8080
  49.  
  50. debug: true
  51.  
  52. <dependency>
  53. <groupId>org.springframework.boot</groupId>
  54. <artifactId>spring-boot-starter-data-redis</artifactId>
  55. </dependency>
  56. <dependency>
  57. <groupId>org.springframework.boot</groupId>
  58. <artifactId>spring-boot-starter-cache</artifactId>
  59. </dependency>
  60.  
  61. {
  62. "timestamp": "2018-04-16T06:34:27.331+0000",
  63. "status": 500,
  64. "error": "Internal Server Error",
  65. "exception":
  66. "org.springframework.http.converter.HttpMessageNotWritableException",
  67. "message": "Could not write JSON: could not initialize proxy - no Session; nested exception is com.fasterxml.jackson.databind.JsonMappingException: could not initialize proxy - no Session (through reference chain:
  68. com.springboot.redis.domains.MyObject$$_jvstdc2_0["id"])",
  69. "path": "/api/myObject/67"
  70. }
Add Comment
Please, Sign In to add comment