我正在用 spring-data-rest 编写一个休息服务。而且我面临一个我不知道如何解决的异常。
我有以下应用程序配置
@Configuration
@ComponentScan(basePackageClasses = Application.class)
@EnableJpaRepositories
@EnableTransactionManagement
public class Application {
@Bean
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder().setType(H2).build();
}
@Bean
public CustomerLoader loadCustomers() {
return new CustomerLoader();
}
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource, JpaVendorAdapter jpaVendorAdapter) {
LocalContainerEntityManagerFactoryBean lef = new LocalContainerEntityManagerFactoryBean();
lef.setDataSource(dataSource);
lef.setJpaVendorAdapter(jpaVendorAdapter);
lef.setPackagesToScan("hello");
return lef;
}
@Bean
public JpaVendorAdapter jpaVendorAdapter() {
HibernateJpaVendorAdapter hibernateJpaVendorAdapter = new HibernateJpaVendorAdapter();
hibernateJpaVendorAdapter.setShowSql(false);
hibernateJpaVendorAdapter.setGenerateDdl(true);
hibernateJpaVendorAdapter.setDatabase(Database.H2);
return hibernateJpaVendorAdapter;
}
@Bean
public PlatformTransactionManager transactionManager() {
return new JpaTransactionManager();
}
这是我的 WebApplication 初始化程序
@Override
public void onStartup(ServletContext ctx)
throws ServletException {
AnnotationConfigWebApplicationContext rootCtx = new AnnotationConfigWebApplicationContext();
rootCtx.register(Application.class);
ctx.addListener(new ContextLoaderListener(rootCtx));
RepositoryRestExporterServlet exporter = new RepositoryRestExporterServlet();
ServletRegistration.Dynamic reg = ctx.addServlet("exporter", exporter);
reg.setLoadOnStartup(1);
reg.addMapping("/*");
}
当我在服务器上运行我的应用程序时,我在 Servlet.init() 上得到以下异常
SEVERE: Servlet /spring-data-rest threw load() exception
java.lang.NoSuchMethodError: org.springframework.data.rest.webmvc.ResourceProcessorInvokingHandlerAdapter.getReturnValueHandlers()Lorg/springframework/web/method/support/HandlerMethodReturnValueHandlerComposite;
(如果你想要完整的堆栈跟踪,请告诉)
我认为由于一些 jar 重复,这将是一些类加载问题。但是我正在使用 maven 构建我的项目,并且我只使用一个存储库(http://repo.spring.io/libs-milestone),其父 pom spring-boot-starter-parent 版本为 0.5.0.M5