在JBoss上发布Spring webapp的问题

时间:2019-03-11 04:07:33

标签: java spring spring-boot jboss

当我尝试部署我的项目时,这给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.undertow.deployment.default-server.default-host./金色:java.lang.RuntimeException:org.springframework.beans.factory.UnsatisfiedDependencyException中的jboss.msc.service.StartException:创建名称为“ greetingController”的bean时出错:通过“发件人”字段表示不满意的依赖关系;嵌套的异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有类型为'co.com.coomeva.golden.service.ws.jms.DistributorSender'的合格Bean:应该至少有1个有资格作为自动装配候选的Bean。依赖项注释:{@ org.springframework.beans.factory.annotation.Autowired(required = true)}       在org.wildfly.extension.undertow.deployment.UndertowDeploymentService $ 1.run(UndertowDeploymentService.java:84)       在java.util.concurrent.Executors $ RunnableAdapter.call(未知来源)       在java.util.concurrent.FutureTask.run(未知来源)       在java.util.concurrent.ThreadPoolExecutor.runWorker(未知来源)       在java.util.concurrent.ThreadPoolExecutor $ Worker.run(未知来源)       在java.lang.Thread.run(未知来源)       在org.jboss.threads.JBossThread.run(JBossThread.java:320)   由以下原因引起: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)}       在io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:241)       在org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:99)       在org.wildfly.extension.undertow.deployment.UndertowDeploymentService $ 1.run(UndertowDeploymentService.java:81)       ...还有6个

    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;
    }

}

3 个答案:

答案 0 :(得分:1)

我转载了您的问题。以下是您需要进行的更改:

  1. @SpringBootApplication(scanBasePackages ={"co.com.coomeva.golden.service.ws.jms","co.com.coomeva.golden.service.ws.main"})
  2. 您需要使用一个{ 像DistributorSender@Component这样的注释。

GoldenServiceApplication.java

@Repository

和DistributorSender.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;
    }

}

答案 1 :(得分:0)

Spring-boot应用程序的一个好习惯:

将您的Application类(带有@SpringBootApplication批注的类)存储在主包上,并将所有其他*.java文件放在此包下,以便Spring Application可以找到它们。

答案 2 :(得分:0)

请删除不必要的注释,@ComponentScan@Configuration@EnableAutoConfiguration

在您有任何特定要求之前,只有下面给出的代码足以运行您的应用程序。

@SpringBootApplication
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;
}