@Converter(autoApply = true) 不适用于不同的包

@Converter(autoApply = true) not working in different package

这是在包下:com.a.b

package com.a.b;
@Converter(autoApply = true)
public class DateConverter implements AttributeConverter<Date, String> {
}

应用程序启动class包下:com.a.c

package com.a.c;
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

在不同的包中,autoApply = true 不工作,除了自定义 LocalContainerEntityManagerFactoryBean。还有其他解决方案吗

您必须使用 @EntityScan。我假设您的实体在 com.a.c 中。如果不是这种情况,您必须设置正确的包:

package com.a.c;

@SpringBootApplication
@EntityScan(basePackages = {"com.a.c", "com.a.b"})
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}