gpt4 book ai didi

java - 刷新了 Spring Boot 上下文中的 Jooq CastException

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:57:24 24 4
gpt4 key购买 nike

spring boot 第一次启动时,jooq 运行良好。但如果我更改代码并在 spring boot 上下文刷新后,然后我遇到了类转换异常的麻烦。问题是在同一个类上抛出异常。

我的启动配置是:

@Autowired
private DataSource dataSource;
public ExecuteListener exceptionTransformer() {
return new DefaultExecuteListener() {
private static final long serialVersionUID = 1L;
@Override
public void exception(ExecuteContext context) {
SQLDialect dialect = context.configuration().dialect();
SQLExceptionTranslator translator = (dialect != null)
? new SQLErrorCodeSQLExceptionTranslator(dialect.name())
: new SQLStateSQLExceptionTranslator();
context.exception(
translator.translate("jOOQ", context.sql(), context.sqlException()));
}
};
}
@Primary
@Bean
public DefaultDSLContext dsl() {
return new DefaultDSLContext(configuration());
}
public DataSourceConnectionProvider connectionProvider() {
return new DataSourceConnectionProvider(new TransactionAwareDataSourceProxy(dataSource));
}
public DefaultConfiguration configuration() {
DefaultConfiguration configuration = new DefaultConfiguration();
configuration.set(connectionProvider());
configuration.set(new DefaultExecuteListenerProvider(exceptionTransformer()));
configuration.set(SQLDialect.MYSQL);
// @formatter:off
configuration.set(
new Settings()
.withExecuteLogging(true)
.withRenderFormatted(true)
);
// @formatter:on
configuration.set(SfmRecordMapperProviderFactory.newInstance().ignorePropertyNotFound().newProvider());
return configuration;
}

查询代码是:

User user = dsl.select()
.from(USER)
.where(USER.USER_ID.eq(id)).fetchOneInto(User.class);

admin.domain.User 是:

@Data
public class User implements Serializable {
private static final long serialVersionUID = 1L;

private String userId;
@JsonIgnore
private String pswd;
private String name;
private String useYn;
private Timestamp registDatetime;
private Timestamp updateDatetime;
}

堆栈跟踪是:

java.lang.ClassCastException: admin.domain.User cannot be cast to admin.domain.User
at admin.dao.UserDao.getUserByIdWithRoles(UserDao.java:123)
at admin.dao.UserDao$$FastClassBySpringCGLIB$$f7b71f39.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:747)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:89)
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)

我有什么错?

最佳答案

关于java - 刷新了 Spring Boot 上下文中的 Jooq CastException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49991934/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com