我是那个倾向于使用Spring Boot编写代码的人。然后,当我尝试编写使用抽象类的代码时,我收到如下错误。Description:Parameter 0 of constructor in com.in28minutes.spring.practice.springmasterclasspractice.devicefactory.
LaptopManufacturingProcess required a bean of type 'java.lang.String' that could not be found.Action:Consider defining a
bean of type 'java.lang.String' in your configuration.你们能告诉我如何解决这个错误吗?Spring Boot:v2.1.4 Java:10.0.2 Maven:3.6.0SpringMasterClassPracticeDeviceFactoryApplication 类import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.boot.SpringApplication;import org.springframework.
boot.autoconfigure.SpringBootApplication;import org.springframework.context.ConfigurableApplicationContext;@SpringBootApplicationpublic
class SpringMasterClassPracticeDeviceFactoryApplication {
private static Logger LOGGER = LoggerFactory.getLogger(SpringMasterClassPracticeDeviceFactoryApplication.class);
public static void main(String[] args) {
ConfigurableApplicationContext applicationContext = SpringApplication
.run(SpringMasterClassPracticeDeviceFactoryApplication.class, args);
ManufacturingImpl manufacturingImpl = applicationContext.getBean(ManufacturingImpl.class);
System.out.println(manufacturingImpl);
// manufacturingImpl.manifactureProduct("Laptop Process");
LOGGER.info("{}", manufacturingImpl);
}}ManufacturingImpl 类import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.factory.
annotation.Qualifier;import org.springframework.stereotype.Component;@Componentpublic class ManufacturingImpl {
@Autowired
@Qualifier("laptop")
private GeneralManufacturingProcess generalManufacturingProcess;
public void manifactureProduct(String processName) {
System.out.println(generalManufacturingProcess);
generalManufacturingProcess.launchProcess();
}}GeneralManufacturingProcess 类public abstract class GeneralManufacturingProcess {
private String processName;
添加回答
举报
0/150
提交
取消