猿问

在 JBoss 上启动 Spring webapp 问题

当我尝试部署我的项目时,这会出现 bean 的问题,我无法解决它,我附上了错误和生成它的类。我需要帮助来解决这个问题。我提前谢谢你。


应用程序无法启动


描述:

co.com.coomeva.golden.service.ws.main.GreetingController 中的字段发件人需要找不到类型为“co.com.coomeva.golden.service.ws.jms.DistributorSender”的 bean。注入点有以下注解:- @org.springframework.beans.factory.annotation.Autowired(required=true) 行动:考虑定义一个 'co.com.coomeva.golden.service.ws.jms.DistributorSender 类型的 bean ' 在您的配置中。22:41:15,280 错误 [org.jboss.msc.service.fail] (ServerService 线程池 -- 69) MSC000001: 无法启动服务 jboss.undertow.deployment.default-server.default-host./Golden: org. jboss.msc.service.StartException 在服务 jboss.undertow.deployment.default-server.default-host./Golden: java.lang.RuntimeException: org.springframework.beans.factory.UnsatisfiedDependencyException: 创建名称为“greetingController”的 bean 时出错:通过字段“sender”表示的依赖关系不满足;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException:没有“co.com.coomeva.golden.service.ws.jms.DistributorSender”类型的合格 bean 可用:预计至少有 1 个有资格作为自动装配候选者的 bean。依赖注释:{@org.springframework.beans.factory.annotation.Autowired(required=true)} at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:84) at java.util.concurrent 


BIG阳
浏览 140回答 3
3回答

杨__羊羊

我转载了你的问题。以下是您需要进行的更改:@SpringBootApplication(scanBasePackages ={"co.com.coomeva.golden.service.ws.jms","co.com.coomeva.golden.service.ws.main"})您需要使用或DistributorSender之类的注释使您的班级具有弹簧意识。@Component@RepositoryGoldenServiceApplication.java@SpringBootApplication(scanBasePackages = {"co.com.coomeva.golden.service.ws.jms","co.com.coomeva.golden.service.ws.main"})public class GoldenServiceApplication extends SpringBootServletInitializer&nbsp;{public static void main(String[] args) {&nbsp; &nbsp; SpringApplication.run(applicationClass, args);}@Overrideprotected SpringApplicationBuilder configure(SpringApplicationBuilder application) {&nbsp; &nbsp; return application.sources(applicationClass);}private static Class<GoldenServiceApplication> applicationClass =&nbsp;GoldenServiceApplication.class;}@RestControllerclass GreetingController {@Autowiredprivate DistributorSender sender;@PostMapping("/distributor/records")public GoldenResponse setGoldenRecord(@RequestBody String goldenRecord)&nbsp;{&nbsp; &nbsp; GoldenResponse response = new GoldenResponse();&nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; sender.publishMessage(goldenRecord);&nbsp; &nbsp; &nbsp; &nbsp; response.setCode(HttpStatus.OK.value());&nbsp; &nbsp; &nbsp; &nbsp; response.setMessage("Golden Record Published");&nbsp; &nbsp; } catch (Exception e) {&nbsp; &nbsp; &nbsp; &nbsp; String error = e.getCause().toString();&nbsp; &nbsp; &nbsp; &nbsp; error = error.length() > 200 ? error.substring(0, 200) : error;&nbsp; &nbsp; &nbsp; &nbsp; response.setMessage("Golden Record was not published. Error:" + error);&nbsp; &nbsp; }&nbsp; &nbsp; return response;}@RequestMapping("/hello/{name}")String hello(@PathVariable String name) {&nbsp; &nbsp; return "Hello, " + name + "!";}@GetMapping("/Example2")public GoldenResponse exampleDist() {&nbsp; &nbsp; GoldenResponse goldenResponse = new GoldenResponse();&nbsp; &nbsp; goldenResponse.setCode(1);&nbsp; &nbsp; goldenResponse.setMessage("sd");&nbsp; &nbsp; System.out.println("Vinagre");&nbsp; &nbsp; return goldenResponse;&nbsp; &nbsp; }}和 DistributorSender.javapackage co.com.coomeva.golden.service.ws.jms;import org.springframework.stereotype.Component;@Componentpublic class DistributorSender {private String record;public void publishMessage(String record) {&nbsp; &nbsp; this.record = record;}}

回首忆惘然

请删除不必要的注释@ComponentScan,@Configuration和@EnableAutoConfiguration在您有任何特定要求之前,只有下面给定的代码足以运行您的应用程序。@SpringBootApplicationpublic class GoldenServiceApplication extends SpringBootServletInitializer {&nbsp; &nbsp; public static void main(String[] args) {&nbsp; &nbsp; &nbsp; &nbsp; SpringApplication.run(applicationClass, args);&nbsp; &nbsp; }&nbsp; &nbsp; @Override&nbsp; &nbsp; protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {&nbsp; &nbsp; &nbsp; &nbsp; return application.sources(applicationClass);&nbsp; &nbsp; }&nbsp; &nbsp; private static Class<GoldenServiceApplication> applicationClass = GoldenServiceApplication.class;}

一只斗牛犬

Spring-boot 应用程序的一个好习惯:将您的 Application 类(具有@SpringBootApplication注释的类)存储在主包中,并将所有其他*.java文件放在该包下,以便 Spring Application 可以找到它们。
随时随地看视频慕课网APP

相关分类

Java
我要回答