当前位置: 首页 > 知识库问答 >
问题:

在JBoss上启动Spring webapp的问题

太叔英锐
2023-03-14

说明:

co.com.coomeva.golden.service.ws.main.GreetingController中的字段发送器需要一个类型为“co.com.coomeva.golden.service.ws.jms.DistributorSender”的bean,但找不到该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.undertow.default-host./golden:org.jboss.deployment.default-server.default-host./golden:jboss.undertow.deployment.default-server.default嵌套异常是org.springframework.beans.factory.nosuchBeanDefinitionException:没有类型为'co.com.coomeva.golden.service.ws.jms.DistributorSender'的合格bean可用:至少需要1个符合autowire候选的bean。依赖项注释:{@org.springframework.beans.factory.annotation.autowire(required=true)}在org.wildfly.extension.undertow.deployment.undertowdeploymentService$1.run(undertowdeploymentService:84)在java.util.concurrent.executors$runnableadapter.call(未知源)在java.util.concurrent.futuretask.run(未知源)在reads.jbossThread.run(jbossThread.java:320)由:java.lang.runtimeException:org.springframework.beans.factory.unsatisfiedDependencyException:创建名为“greeting controller”的bean时出错:通过字段“sender”表示的未满足依赖关系;嵌套异常是org.springframework.beans.factory.nosuchBeanDefinitionException:没有类型为'co.com.coomeva.golden.service.ws.jms.DistributorSender'的合格bean可用:至少需要1个符合autowire候选的bean。依赖项注释:{@org.springframework.beans.factory.annotation.autowire(required=true)}在io.undertow.servlet.core.deploymentManagerimpl.deploymentManagerimpl.deploymentManagerimpl.deploymentManagerimpl.java:241)在org.wildfly.extension.undertow.deployment.deployment.deployment.java:241)在

    package co.com.coomeva.golden.service.ws.main;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import co.com.coomeva.golden.service.ws.jms.*;
import co.com.coomeva.golden.service.ws.model.GoldenResponse;

@Configuration
@ComponentScan
@EnableAutoConfiguration
@SpringBootApplication(scanBasePackages = { "co.com.coomeva.golden.service.ws.controllers", "co.com.coomeva.golden.service.ws.jms.DistributorSender"})
public class GoldenServiceApplication extends SpringBootServletInitializer {

    public static void main(String[] args) {
        SpringApplication.run(applicationClass, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(applicationClass);
    }

    private static Class<GoldenServiceApplication> applicationClass = GoldenServiceApplication.class;
}

@RestController
class GreetingController {

    @Autowired
    private DistributorSender sender;

    @PostMapping("/distributor/records")
    public GoldenResponse setGoldenRecord(@RequestBody String goldenRecord) {
        GoldenResponse response = new GoldenResponse();

        try {
            sender.publishMessage(goldenRecord);
            response.setCode(HttpStatus.OK.value());
            response.setMessage("Golden Record Published");
        } catch (Exception e) {
            String error = e.getCause().toString();
            error = error.length() > 200 ? error.substring(0, 200) : error;
            response.setMessage("Golden Record was not published. Error:" + error);
        }

        return response;
    }

    @RequestMapping("/hello/{name}")
    String hello(@PathVariable String name) {
        return "Hello, " + name + "!";
    }

    @GetMapping("/Example2")
    public GoldenResponse exampleDist() {
        GoldenResponse goldenResponse = new GoldenResponse();
        goldenResponse.setCode(1);
        goldenResponse.setMessage("sd");
        System.out.println("Vinagre");
        return goldenResponse;
    }

}

共有1个答案

齐乐逸
2023-03-14

我复制了你的问题。以下是您需要进行的更改:

  1. @SpringBootApplication(scanBasePackages={“co.com.coomeva.golden.service.ws.jms”,“co.com.coomeva.golden.service.ws.main”})
  2. 您需要使用诸如@component@repository之类的注释使DistributorSender类能够感知spring。

java GoldenServiceApplication.java

@SpringBootApplication(scanBasePackages = {"co.com.coomeva.golden.service.ws.jms","co.com.coomeva.golden.service.ws.main"})
public class GoldenServiceApplication extends SpringBootServletInitializer 
{

public static void main(String[] args) {
    SpringApplication.run(applicationClass, args);
}

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(applicationClass);
}

private static Class<GoldenServiceApplication> applicationClass = 
GoldenServiceApplication.class;
}

@RestController
class GreetingController {

@Autowired
private DistributorSender sender;

@PostMapping("/distributor/records")
public GoldenResponse setGoldenRecord(@RequestBody String goldenRecord) 
{
    GoldenResponse response = new GoldenResponse();

    try {
        sender.publishMessage(goldenRecord);
        response.setCode(HttpStatus.OK.value());
        response.setMessage("Golden Record Published");
    } catch (Exception e) {
        String error = e.getCause().toString();
        error = error.length() > 200 ? error.substring(0, 200) : error;
        response.setMessage("Golden Record was not published. Error:" + error);
    }

    return response;
}

@RequestMapping("/hello/{name}")
String hello(@PathVariable String name) {
    return "Hello, " + name + "!";
}

@GetMapping("/Example2")
public GoldenResponse exampleDist() {
    GoldenResponse goldenResponse = new GoldenResponse();
    goldenResponse.setCode(1);
    goldenResponse.setMessage("sd");
    System.out.println("Vinagre");
    return goldenResponse;
    }

}
package co.com.coomeva.golden.service.ws.jms;

import org.springframework.stereotype.Component;

@Component
public class DistributorSender {
private String record;

public void publishMessage(String record) {
    this.record = record;
}

}
 类似资料:
  • 问题内容: 以前的JBoss版本包含一个脚本(如),可以将其复制到/etc/init.d以便将其添加为服务- 因此它将在启动时启动。我似乎在JBoss 7中找不到任何类似的脚本。有人做过这样的事情吗? PS我正在尝试在Ubuntu 10.04中实现这一点 问题答案: 在花了几个小时的窥探之后,我最终创建了以下内容 这是内容: 和: 显然,您需要确保将JAVA_HOME和JBOSS_HOME设置为适

  • 我正在尝试启动JBoss[EAP]4.3.0。GA_CP06但收到错误未知主机异常,如下日志所示。我建议将IP和主机名映射到etc/hosts文件中,但管理员说这是DHCP,所以没有必要按照我的建议映射。听起来正确,对吗?有什么建议可以克服这个错误吗? 更新: JBoss引导环境 JBOSS_HOME:/disk01/HOME/dmadmin/JBOSS-eap-4.3-src/JBOSS-as

  • 问题内容: EJB似乎是延迟加载的-每当访问时。 但是,我想热切地初始化它们-即每当容器启动时。如何实现的(特别是在JBoss中) 该主题提供了一些提示,但并不令人满意。 问题答案: 从EJB 3.1开始,可以将模块启动和停止通知单例bean: 在EJB 3.1之前,没有标准的纯EJB解决方案。我建议将WAR添加到您的EAR并使用servlet-context-listener。

  • 在jboss上部署spring boot项目之后,除了我的日程安排任务之外,一切都很顺利。我在我的schedule方法类中用@enablescheduling和@component注释了我的主类,在我的方法中用@scheduled注释了我的主类。但在jboss上成功运行且无错误后,我的计划任务不会启动。我真的需要一个解决方案。Tnx下面的每个主体都是我的配置类和日程类:

  • 环境:-Spring Boot 1.5.2(war)-java 1.7 -jboss EAP 6.3 在jboss EAP上运行spring boot应用程序war时,我遇到以下错误: 这里列出了相同的问题,但没有提到如何使用Jboss EAP 6.3。 谢谢你的帮助!

  • 问题内容: 我们从JBoss 4(和JDK 5)升级到JBoss 5(和JDK 6)。问题是开始时间已经从1.5分钟(在JBoss 4上)增加到4分钟以上。 似乎花费JBoss最长时间来初始化的组件是JMX 从调试服务器日志中,我在有问题的时间得到以下行: 项目中没有EJB。 内存设置为: 您是否知道如何改善JBoss的启动时间? 更新: 到目前为止没有运气,我尝试了shreeni的建议(更改了扫