1
@Service
public interface DatabaseConnector {
    public Model getModel();
}

@Configuration
@Profile({"!test"})
public class DatabaseConnectorT implements DatabaseConnector {

    private final Model model;

    @Autowired
    public DatabaseConnectorT(@Value("${assemblerFile}") String assemblerFile) {
        model = TDBFactory.assembleModel(assemblerFile);
    }
}

I am getting the error, that this bean class cannot be instantiated and a default constructor should be given. Why should such one be required? I have two different implementations of the interface which should be loaded dependent on the active profile. Configuration should be done with annotations.

Chris
  • 89
  • 1
  • 10

1 Answers1

0

Default constructor is a constructor without parameters.

According to the error message I suppose that the class is being created via reflection. So you must provide a way to create a class via reflection.

I assumed the value of assemblerFile in your constructor can't be determined via reflection and so the default constructor is called instead, which is not provided.

Drejc
  • 14,196
  • 16
  • 71
  • 106