We help IT Professionals succeed at work.

Consider defining a bean named in your configuration.

hi am having error in my spring boot
log4j:WARN No appenders could be found for logger (org.jboss.logging).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
663 [main] INFO ncs.app.co.za.NcsApp - Starting NcsApp on Desmand-PC with PID 17780 (C:\projects\NcsApp\bin started by user in C:\projects\NcsApp)
663 [main] INFO ncs.app.co.za.NcsApp - No active profile set, falling back to default profiles: default
2072 [main] INFO ncs.app.co.za.NcsApp - Started NcsApp in 1.948 seconds (JVM running for 2.427)
2074 [main] INFO org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener -

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2182 [main] ERROR org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter -

***************************
APPLICATION FAILED TO START
***************************

Description:

A component required a bean named 'NocIigJDBCTemplate' that could not be found.


Action:

Consider defining a bean named 'NocIigJDBCTemplate' in your configuration.

package ncs.app.co.za;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource;

@SpringBootApplication
public class NcsApp {
	
	@Autowired
	NocIigJDBCTemplate iigJDBCTempalate;
	

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		SpringApplication.run(NcsApp.class, args);

	}
	
	@Bean
	public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
		return args -> {
			final NocIigJDBCTemplate iigJDBCTempalate = (NocIigJDBCTemplate) ctx.getBean("NocIigJDBCTemplate");
			System.out.println("Listing iig records : ");
			iigJDBCTempalate.displayEmpList();
		};
	}

}

Open in new window

Comment
Watch Question

CERTIFIED EXPERT

Commented:
NocIigJDBCTemplate  is that your own bean ? or ?
CERTIFIED EXPERT

Commented:
if your own bean then you need to use annotation for that class @component like that

if its your existing then import that

Author

Commented:
i did this
package com.app.co.za;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource;
//@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}, scanBasePackages = {
	//	"ncs.app.co.za"
//})
//@ImportResource({ "classpath*:AppConfig.xml" })
@SpringBootApplication
public class NcsApp {
	
	@Autowired
	NocIigJDBCTemplate iigJDBCTempalate;
	

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		SpringApplication.run(NcsApp.class, args);

	}
	
	@Bean
	public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
		return args -> {
			final NocIigJDBCTemplate iigJDBCTempalate = (NocIigJDBCTemplate) ctx.getBean("NocIigJDBCTemplate");
			System.out.println("Listing iig records : ");
			iigJDBCTempalate.displayEmpList();
		};
	}

}

Open in new window

log4j:WARN No appenders could be found for logger (org.jboss.logging).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
3444 [main] INFO com.co.za.app - Starting app on Desmand-PC with PID 5800 (C:\projects\app\bin started by user in C:\projects\app)
3445 [main] INFO com.co.za.app - No active profile set, falling back to default profiles: default
7789 [main] INFO com.co.za.app - Started app in 7.41 seconds (JVM running for 9.383)
7793 [main] INFO org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener -

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
7933 [main] ERROR org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter -

***************************
APPLICATION FAILED TO START
***************************

Description:

A component required a bean named 'NocIigJDBCTemplate' that could not be found.


Action:

Consider defining a bean named 'NocIigJDBCTemplate' in your configuration.
CERTIFIED EXPERT
Commented:
add that package in @componetscan