Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @GetMapping(value = "{id}", produces = MediaType.APPLICATION_JSON_VALUE)
- public ResponseEntity<MyObject> getDataById(@PathVariable(value = "id") Integer id)
- {
- MyObject data = myService.findOneById(String.valueOf(id));
- return Optional.ofNullable(data)
- .map(mData -> new ResponseEntity<>(mData, HttpStatus.OK))
- .orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));
- }
- @Cacheable(value = "mydata", key = "#id")
- public MyObject findOneById(String id) {
- return myRepository.getOne(Integer.valueOf(id));
- }
- spring:
- application:
- name: Spring Boot Caching With Redis
- datasource:
- driver-class-name: com.mysql.jdbc.Driver
- url: jdbc:mysql://localhost/redis?useUnicode=true&characterEncoding=utf8&useSSL=false
- name:
- username: root
- password: root
- hikari:
- data-source-properties:
- cachePrepStmts: true
- prepStmtCacheSize: 250
- prepStmtCacheSqlLimit: 2048
- useServerPrepStmts: true
- jpa:
- database-platform: org.hibernate.dialect.MySQLInnoDBDialect
- database: MYSQL
- show_sql: false
- properties:
- hibernate.cache.use_second_level_cache: false
- hibernate.cache.use_query_cache: false
- hibernate.generate_statistics: true
- jackson:
- serialization:
- write_dates_as_timestamps: false
- cache:
- type: redis
- liquibase:
- change-log: classpath:liquibase/master.xml
- server:
- port: 8080
- debug: true
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-data-redis</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-cache</artifactId>
- </dependency>
- {
- "timestamp": "2018-04-16T06:34:27.331+0000",
- "status": 500,
- "error": "Internal Server Error",
- "exception":
- "org.springframework.http.converter.HttpMessageNotWritableException",
- "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:
- com.springboot.redis.domains.MyObject$$_jvstdc2_0["id"])",
- "path": "/api/myObject/67"
- }
Add Comment
Please, Sign In to add comment