3 回答
TA贡献1943条经验 获得超7个赞
我转载了你的问题。以下是您需要进行的更改:
@SpringBootApplication(scanBasePackages ={"co.com.coomeva.golden.service.ws.jms","co.com.coomeva.golden.service.ws.main"})
您需要使用或
DistributorSender
之类的注释使您的班级具有弹簧意识。@Component
@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;
}
}
和 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;
}
}
TA贡献1847条经验 获得超11个赞
请删除不必要的注释@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;
}
TA贡献1784条经验 获得超2个赞
Spring-boot 应用程序的一个好习惯:
将您的 Application 类(具有@SpringBootApplication
注释的类)存储在主包中,并将所有其他*.java
文件放在该包下,以便 Spring Application 可以找到它们。
添加回答
举报