I am using jdk8 and need to create a spring-component that will take class-name as constructor argument. However, with my current code I am getting runtime error:
Parameter 0 of constructor in com.some.MyLogger required a bean of type 'java.lang.String' that could not be found
This is my MyLogger class:
@Component
public class MyLogger {
protected final Log logger;
public MyLogger(String clazz) {
logger = LogFactory.getLog(clazz);
}
public void debug(String format, Object... args)
{
if (logger.isDebugEnabled())
{
logger.debug(String.format(format, args));
}
}
public void info(String msg)
{
logger.debug(msg);
}
}
And this is how I am trying to create the class:
@SpringBootApplication
public class Application {
public static void main(String[] args) throws MalformedURLException {
ApplicationContext context = SpringApplication.run(Application.class, args);
MyLogger logger = (MyLogger) context.getBean(MyLogger.class, Application.class.getCanonicalName());
logger.info("================ I AM HERE ====================");
}
May I get any insight on right way of creating this component / What's going wrong here ? Thanks in advance.