- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在构建一个使用并返回 JSON 的 RESTful Web 服务。当我尝试通过服务层从数据库中获取 ESRBRating 对象时,我遇到了以下堆栈跟踪。但是,当我将 Spring Data JPA 存储库直接注入(inject) Controller 并使用它按 ID 获取 ESRBRating 时,它工作正常。但是,当通过服务层调用时,它不起作用。我在下面提供了堆栈跟踪和代码。有人可以向我解释为什么在通过服务层而不是直接通过 Spring Data JPA 存储库时会发生这种情况吗?我该如何解决这个问题?
堆栈跟踪
Caused by: org.hibernate.LazyInitializationException: could not initialize proxy - no Session
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:165)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:286)
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:185)
at net.jkratz.igdb.model.ESRBRating_$$_jvst319_0.getId(ESRBRating_$$_jvst319_0.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:466)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:639)
... 76 more
@RestController
@RequestMapping(produces = "application/json", value="/esrbrating")
public class ESRBRatingController {
@Inject
ESRBRatingService esrbRatingService;
@Inject
ESRBRatingRepository esrbRatingRepository;
private Logger logger = LoggerFactory.getLogger(getClass());
/**
* Returns all ESRB ratings in database
*
* @return List of ESRBRating objects
* @see ESRBRating
*/
@RequestMapping(value = {"","/"}, method = RequestMethod.GET)
public ResponseEntity<List<ESRBRating>> getESRBRatings() {
List<ESRBRating> esrbRatings = esrbRatingService.getESRBRatings();
return new ResponseEntity<>(esrbRatings, HttpStatus.OK);
}
/**
* Returns a single ESRB rating object if exists, otherwise returns HTTP status code 404
*
* @param id ID of the ESRB Rating
* @return ESRB Rating when found
* @see ESRBRating
*/
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public ResponseEntity<?> getUser(@PathVariable("id") Long id) {
logger.debug("Attempting to fetch ESRB rating with ID: {}", id);
ESRBRating esrbRating = esrbRatingService.getESRBRating(id);
//ESRBRating esrbRating = esrbRatingRepository.findOne(id);
if (esrbRating == null) {
return new ResponseEntity<>("ESRB Rating not found", HttpStatus.NOT_FOUND);
} else {
return new ResponseEntity<>(esrbRating, HttpStatus.OK);
}
}
}
@Service
@Transactional
public class ESRBRatingServiceImpl implements ESRBRatingService {
@Value("#{paging.games.maxPageSize}")
private static int DEFAULT_PAGE_SIZE;
@Value("#{paging.games.maxPageSize}")
private static int MAX_PAGE_SIZE;
@Inject
private ESRBRatingRepository esrbRatingRepository;
@Override
public List<ESRBRating> getESRBRatings() {
List<ESRBRating> ratings = esrbRatingRepository.findAll();
return ratings;
}
@Override
public ESRBRating getESRBRating(Long id) {
return esrbRatingRepository.getOne(id);
}
@Override
public ESRBRating saveESRBRating(ESRBRating esrbRating) {
return esrbRatingRepository.saveAndFlush(esrbRating);
}
@Override
public boolean deleteESRBRating(Long id) {
esrbRatingRepository.delete(id);
return true;
}
}
package net.jkratz.igdb.repository;
import net.jkratz.igdb.model.ESRBRating;
import org.springframework.data.jpa.repository.JpaRepository;
public interface ESRBRatingRepository extends JpaRepository<ESRBRating, Long> {
}
@Entity
@Table(name = "esrb_rating", schema = "igdb")
@JsonIgnoreProperties(ignoreUnknown = true)
public class ESRBRating implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@NotNull
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", nullable = false)
private Long id;
@NotNull
@Size(min = 1, max = 255)
@Column(name = "title", nullable = false, length = 255)
private String title;
@Size(max = 65535)
@Column(length = 65535)
private String description;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "esrbRating")
private List<Game> games;
public ESRBRating() {
}
public ESRBRating(Long id, String title, String description) {
this.id = id;
this.title = title;
this.description = description;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ESRBRating that = (ESRBRating) o;
return Objects.equal(this.id, that.id) &&
Objects.equal(this.title, that.title) &&
Objects.equal(this.description, that.description);
}
@Override
public int hashCode() {
return Objects.hashCode(id, title, description);
}
@Override
public String toString() {
return Objects.toStringHelper(this)
.add("id", id)
.add("title", title)
.add("description", description)
.toString();
}
}
@RestController
@RequestMapping(produces = "application/json", value="/esrbrating")
public class ESRBRatingController {
@Inject
ESRBRatingService esrbRatingService;
@Inject
ESRBRatingRepository esrbRatingRepository;
private Logger logger = LoggerFactory.getLogger(getClass());
/**
* Returns all ESRB ratings in database
*
* @return List of ESRBRating objects
* @see ESRBRating
*/
@RequestMapping(value = {"","/"}, method = RequestMethod.GET)
public ResponseEntity<List<ESRBRating>> getESRBRatings() {
List<ESRBRating> esrbRatings = esrbRatingService.getESRBRatings();
return new ResponseEntity<>(esrbRatings, HttpStatus.OK);
}
/**
* Returns a single ESRB rating object if exists, otherwise returns HTTP status code 404
*
* @param id ID of the ESRB Rating
* @return ESRB Rating when found
* @see ESRBRating
*/
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public ResponseEntity<?> getUser(@PathVariable("id") Long id) {
logger.debug("Attempting to fetch ESRB rating with ID: {}", id);
ESRBRating esrbRating = esrbRatingRepository.findOne(id);
if (esrbRating == null) {
return new ResponseEntity<>("ESRB Rating not found", HttpStatus.NOT_FOUND);
} else {
return new ResponseEntity<>(esrbRating, HttpStatus.OK);
}
}
org.springframework.http.converter.HttpMessageNotWritableException: Could not write content: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: net.jkratz.igdb.model.ESRBRating_$$_jvstb5c_0["handler"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: net.jkratz.igdb.model.ESRBRating_$$_jvstb5c_0["handler"])
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:238)
at org.springframework.http.converter.AbstractHttpMessageConverter.write(AbstractHttpMessageConverter.java:208)
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodProcessor.writeWithMessageConverters(AbstractMessageConverterMethodProcessor.java:158)
at org.springframework.web.servlet.mvc.method.annotation.HttpEntityMethodProcessor.handleReturnValue(HttpEntityMethodProcessor.java:138)
at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:71)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:122)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:781)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:721)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter.doFilter(DefaultLoginPageGeneratingFilter.java:155)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.fasterxml.jackson.databind.JsonMappingException: No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationFeature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: net.jkratz.igdb.model.ESRBRating_$$_jvstb5c_0["handler"])
at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:59)
at com.fasterxml.jackson.databind.ser.impl.UnknownSerializer.serialize(UnknownSerializer.java:26)
at com.fasterxml.jackson.databind.ser.BeanPropertyWriter.serializeAsField(BeanPropertyWriter.java:505)
at com.fasterxml.jackson.databind.ser.std.BeanSerializerBase.serializeFields(BeanSerializerBase.java:639)
at com.fasterxml.jackson.databind.ser.BeanSerializer.serialize(BeanSerializer.java:152)
at com.fasterxml.jackson.databind.ser.DefaultSerializerProvider.serializeValue(DefaultSerializerProvider.java:114)
at com.fasterxml.jackson.databind.ObjectMapper.writeValue(ObjectMapper.java:1887)
at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.writeInternal(AbstractJackson2HttpMessageConverter.java:231)
... 72 more
@Entity
@Table(name = "esrb_rating", schema = "igdb")
@JsonIgnoreProperties(ignoreUnknown = false)
@Proxy(lazy = false)
public class ESRBRating implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@NotNull
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", nullable = false)
private Long id;
@NotNull
@Size(min = 1, max = 255)
@Column(name = "title", nullable = false, length = 255)
private String title;
@Size(max = 65535)
@Column(length = 65535)
private String description;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "esrbRating")
private List<Game> games;
public ESRBRating() {
}
public ESRBRating(Long id, String title, String description) {
this.id = id;
this.title = title;
this.description = description;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@JsonIgnore
public List<Game> getGames() {
return games;
}
public void setGames(List<Game> games) {
this.games = games;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ESRBRating that = (ESRBRating) o;
return Objects.equal(this.id, that.id) &&
Objects.equal(this.title, that.title) &&
Objects.equal(this.description, that.description);
}
@Override
public int hashCode() {
return Objects.hashCode(id, title, description);
}
@Override
public String toString() {
return Objects.toStringHelper(this)
.add("id", id)
.add("title", title)
.add("description", description)
.toString();
}
}
@Entity
@Table(name = "game", schema = "igdb",
indexes = {@Index(name = "idx_game_title", columnList = ("title"), unique = false),
@Index(name = "idx_game_developer", columnList = ("developer"), unique = false),
@Index(name = "idx_game_publisher", columnList = ("publisher"), unique = false)})
@JsonIgnoreProperties(ignoreUnknown = true)
public class Game implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@NotNull
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", nullable = false)
private Long id;
@NotNull
@Size(min = 1, max = 255)
@Column(name = "title", nullable = false, length = 255)
private String title;
@Size(max = 65535)
@Column(name = "description", length = 65535)
private String description;
@Size(max = 255)
@Column(name = "developer", length = 255)
private String developer;
@Size(max = 255)
@Column(name = "publisher", length = 255)
private String publisher;
@NotNull
@Size(max = 4)
@Column(name = "players", nullable = false)
private short players;
@NotNull
@Column(name = "cooperative", nullable = false)
private boolean cooperative;
@NotNull
@Column(name = "release_date", nullable = false)
@Temporal(TemporalType.DATE)
private Date releaseDate;
@Size(max = 255)
@Column(name = "image", length = 255)
private String image;
@JoinColumn(name = "esrb_rating_id", referencedColumnName = "id", nullable = false)
@ManyToOne(optional = false, fetch = FetchType.EAGER)
private ESRBRating esrbRating;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "game")
private List<GamePlatformMap> gamePlatformMap;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "game")
private List<GameGenreMap> gameGenreMap;
public Game() {
}
public Game(Long id, String title, String description, String developer,
String publisher, short players, boolean cooperative,
Date releaseDate, String image, ESRBRating esrbRating) {
super();
this.id = id;
this.title = title;
this.description = description;
this.developer = developer;
this.publisher = publisher;
this.players = players;
this.cooperative = cooperative;
this.releaseDate = releaseDate;
this.image = image;
this.esrbRating = esrbRating;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getDeveloper() {
return developer;
}
public void setDeveloper(String developer) {
this.developer = developer;
}
public String getPublisher() {
return publisher;
}
public void setPublisher(String publisher) {
this.publisher = publisher;
}
public short getPlayers() {
return players;
}
public void setPlayers(short players) {
this.players = players;
}
public boolean isCooperative() {
return cooperative;
}
public void setCooperative(boolean cooperative) {
this.cooperative = cooperative;
}
public Date getReleaseDate() {
return releaseDate;
}
public void setReleaseDate(Date releaseDate) {
this.releaseDate = releaseDate;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public ESRBRating getEsrbRating() {
return esrbRating;
}
public void setEsrbRating(ESRBRating esrbRating) {
this.esrbRating = esrbRating;
}
@JsonIgnore
public List<GamePlatformMap> getGamePlatformMap() {
return gamePlatformMap;
}
public void setGamePlatformMap(List<GamePlatformMap> gamePlatformMap) {
this.gamePlatformMap = gamePlatformMap;
}
@JsonIgnore
public List<GameGenreMap> getGameGenreMap() {
return gameGenreMap;
}
public void setGameGenreMap(List<GameGenreMap> gameGenreMap) {
this.gameGenreMap = gameGenreMap;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Game that = (Game) o;
return Objects.equal(this.id, that.id) &&
Objects.equal(this.title, that.title) &&
Objects.equal(this.description, that.description) &&
Objects.equal(this.developer, that.developer) &&
Objects.equal(this.publisher, that.publisher) &&
Objects.equal(this.players, that.players) &&
Objects.equal(this.cooperative, that.cooperative) &&
Objects.equal(this.releaseDate, that.releaseDate) &&
Objects.equal(this.image, that.image) &&
Objects.equal(this.esrbRating, that.esrbRating);
}
@Override
public int hashCode() {
return Objects.hashCode(id, title, description, developer, publisher, players,
cooperative, releaseDate, image, esrbRating);
}
@Override
public String toString() {
return Objects.toStringHelper(this)
.add("id", id)
.add("title", title)
.add("description", description)
.add("developer", developer)
.add("publisher", publisher)
.add("players", players)
.add("cooperative", cooperative)
.add("releaseDate", releaseDate)
.add("image", image)
.add("esrbRating", esrbRating)
.toString();
}
}
最佳答案
首先根据jackson-core版本下载jackson-datatype-hibernate4-2.2.3.jar或更高版本。然后在配置文件中使用此代码,您可以使用 fetch strategy LAZY 而不会出现任何错误。
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.hibernate4.Hibernate4Module;
public class ApplicationConfig extends WebMvcConfigurerAdapter
{
public MappingJackson2HttpMessageConverter jacksonMessageConverter(){
MappingJackson2HttpMessageConverter messageConverter = new MappingJackson2HttpMessageConverter();
ObjectMapper mapper = new ObjectMapper();
//Registering Hibernate4Module to support lazy objects
mapper.registerModule(new Hibernate4Module());
messageConverter.setObjectMapper(mapper);
return messageConverter;
}
@Override
public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
//Here we add our custom-configured HttpMessageConverter
converters.add(jacksonMessageConverter());
super.configureMessageConverters(converters);
}
关于JsonMappingException : could not initialize proxy - no Session,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26957554/
是否为每个 Shiny session 分配了 session ID/ session key (如果部署在 Shiny 服务器上)?如果是,我如何访问该信息?我已阅读文档here然而上网查了一下,并
我正在使用 this koajs session 模块。 我检查了源代码,但我真的无法理解。 我想知道它保存 session 数据的位置,因为我没有看到创建的文件,并且当服务器重新启动时, sessi
实现高可扩展性的一种方法是使用网络负载平衡在多个服务器之间分配处理负载。 这种方法提出的一个挑战是服务器是否具有状态意识 - 将用户状态存储在“ session ”中。 此问题的一个解决方案是“粘性
在负载平衡服务器的上下文中, session 亲和性和粘性 session 之间有什么区别? 最佳答案 我见过这些术语可以互换使用,但有不同的实现方式: 在第一个响应中发送 cookie,然后在后续响
我希望其他人向我解释哪种方法更好:使用 session 或设计无 session 。我们正在开始开发一个新的 Web 应用程序,但尚未决定要遵循什么路径。 无 session 设计在我看来更可取: 优
现在用户在他的权限中有很多角色,我将允许他点击 href 并在新窗口中扮演另一个角色。每个角色都有自己的 session 。 既然浏览器打开窗口不能用新 session 打开,我必须在服务器端想办法。
我正在尝试为express.js Node 应用程序实现 session 存储我的问题是: 如何删除具有浏览器 session 生命周期的 cookie(根据连接文档标记有 expires = fal
在开始在 golang 中使用 session 之前,我需要回答一些问题 session 示例 import "github.com/gorilla/sessions" var store = ses
我读过 Namespaced Attributes . 我尝试使用此功能: #src/Controller/CartController.php public function addProduct(
我正在努力完成以下工作: 根据用户的类型更改用户的 session cookie 到期日期。 我有一个 CakePHP Web 应用程序,其中我使用 CakePHP session 创建了我的身份验证
这是我在这里的第一个问题,我希望我做对了。 我需要处理一个 Java EE 项目,所以在开始之前,我会尝试做一些简单的事情,看看我是否能做到。 我坚持使用有状态 session Bean。 这是问题:
ColdFusion session 与 J2EE session 相比有什么优势吗? ColdFusion session documentation提到了 J2EE session 的优点,但没有
在执行任何任务之前,我需要准确地在创建 session 时创建一个 session 范围变量(因为我的所有任务都需要一个初始 session 范围变量才能运行)。因为,创建 session 时,gra
我们当前的应用使用 HTTP session ,我们希望将其替换为 JWT。 该设置仅允许每个用户进行一次 session 。这意味着: 用户在设备 1 上登录 用户已在设备 1 上登录(已创建新 s
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
假设我在两个或更多设备上打开了两个或更多用户 session (同一用户没有管理员权限)。 在当前 session 中,如果我注销,是否意味着所有其他 session 也会关闭?如果没有,有没有办法通
我正在评估在 tomcat 中使用带有 session 复制的粘性 session 的情况。根据我的初步评估,我认为如果我们启用 session 复制,那么在一个 tomcat 节点中启动的 sess
我开始使用 golang 和 Angular2 构建一个常规的网络应用程序,最重要的是我试图在 auth0.com 的帮助下保护我的登录.我从 here 下载快速入门代码并尝试运行代码,它运行了一段时
我在 Spring Controller 中有一个方法,它接受两个相同类型的参数其中一个来自 session ,另一个来自表单提交(UI)。 问题是在 Controller 方法中我的非 sessio
在我登录之前,我可以点击我的安全约束目录之外的任何内容。如果我尝试转到安全约束目录内的某个位置,它会将我重定向到表单登录页面。如您所料。 登录后,我可以继续我的业务,并访问我的安全约束内外的资源。
我是一名优秀的程序员,十分优秀!