猿问

我怎么能在spring框架上使用抽象类?

我是那个倾向于使用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.0

SpringMasterClassPracticeDeviceFactoryApplication 类

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;



桃花长相依
浏览 1178回答 2
2回答

哆啦的时光机

generalManufacturingProcess是一个抽象类,无法实例化
随时随地看视频慕课网APP

相关分类

Java
我要回答