我正在尝试遵循本教程:https://www.baeldung.com/olingo 在教程代码中,JerseyConfig类只有一个带有2个参数的构造函数,但这会导致“无默认构造函数错误”
如果我添加一个默认的构造函数,那么该项目将正确构建,但是显然参数化构造函数中的代码不会运行,并且在尝试查询时我只会得到404
public JerseyConfig(CarsODataJPAServiceFactory serviceFactory, EntityManagerFactory emf) {
System.out.println("************* JERSEY CONFIG MAIN ***********************");
ODataApplication app = new ODataApplication();
app
.getClasses()
.forEach( new Consumer<Class<?>>()
{
@Override
public void accept(Class<?> c)
{
// Avoid using the default RootLocator, as we want
// a Spring Managed one
if ( !ODataRootLocator.class.isAssignableFrom(c)) {
register(c);
}
}
});
register(new CarsRootLocator(serviceFactory));
register( new EntityManagerFilter(emf));
}
相关错误:
org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.baeldung.examples.olingo2.JerseyConfig]: No default constructor found; nested exception is java.lang.NoSuchMethodException: org.baeldung.examples.olingo2.JerseyConfig.<init>()