Spring Boot Jar to war [英] Spring boot Jar to war
问题描述
我正在尝试更改 spring 音乐应用程序 (https://github.com/cloudfoundry-samples/spring-music) 从 jar 到 war 文件以在 Liberty 中进行测试.我做了以下更改
I am trying to change the spring music application (https://github.com/cloudfoundry-samples/spring-music) from jar to war file to test in Liberty. I did the following change
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
还有 build.gradle
and also build.gradle
apply plugin: 'war'
dependencies {
// Spring Boot
compile("org.springframework.boot:spring-boot-starter-web")
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
}
war 文件已经创建,但是在尝试访问应用程序时,它给出了错误由以下原因引起:org.springframework.beans.factory.NoSuchBeanDefinitionException:找不到类型为 [org.springframework.data.repository.CrudRepository] 的合格 bean 依赖项:预计至少有 1 个 bean 有资格作为此依赖项的自动装配候选者.依赖注释:{}
The war files get created,but while trying to access the application,it gives the error Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.data.repository.CrudRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
我在这里遗漏了什么吗?
Am I missing anything here ?
推荐答案
如果你想使用 CrudRepository 你需要添加一个依赖到spring-boot-starter-data-jpa 之类的
If you want to use CrudRepository you need to add a dependency to spring-boot-starter-data-jpa like
compile("org.springframework.boot:spring-boot-starter-data-jpa")
这篇关于Spring Boot Jar to war的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!