Reputation: 37
When i trying to deploy my project, this presents a problem with the bean, i have not been able to solve it, i attach the error and the class that generates it. I need help to solve this please. I thank you in advance.
APPLICATION FAILED TO START
Description:
Field sender in co.com.coomeva.golden.service.ws.main.GreetingController required a bean of type 'co.com.coomeva.golden.service.ws.jms.DistributorSender' that could not be found. The injection point has the following annotations:- @org.springframework.beans.factory.annotation.Autowired(required=true) Action:Consider defining a bean of type 'co.com.coomeva.golden.service.ws.jms.DistributorSender' in your configuration. 22:41:15,280 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 69) MSC000001: Failed to start service jboss.undertow.deployment.default-server.default-host./Golden: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./Golden: java.lang.RuntimeException: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'greetingController': Unsatisfied dependency expressed through field 'sender'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'co.com.coomeva.golden.service.ws.jms.DistributorSender' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:84) at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) at java.util.concurrent.FutureTask.run(Unknown Source) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.lang.Thread.run(Unknown Source) at org.jboss.threads.JBossThread.run(JBossThread.java:320) Caused by: java.lang.RuntimeException: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'greetingController': Unsatisfied dependency expressed through field 'sender'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'co.com.coomeva.golden.service.ws.jms.DistributorSender' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:241) at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:99) at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:81) ... 6 more
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;
}
}
Upvotes: 2
Views: 1347
Reputation: 49
A good practice for Spring-boot applications:
Store your Application class (the one that has the @SpringBootApplication
annotation) on the main package, and put all other *.java
files under this package, so Spring Application could find them.
Upvotes: 0
Reputation: 86
I reproduced your issue. Below are the changes you need to make:
@SpringBootApplication(scanBasePackages ={"co.com.coomeva.golden.service.ws.jms","co.com.coomeva.golden.service.ws.main"})
DistributorSender
class spring aware with an
annotation like @Component
or @Repository
.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;
}
}
and DistributorSender.java
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;
}
}
Upvotes: 1
Reputation:
Please remove unnecessary annotation,@ComponentScan
,@Configuration
and @EnableAutoConfiguration
Only below given code is sufficient to run your application until you have any specific requirement.
@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;
}
Upvotes: 0