Reputation: 1
I have created a simple Spring core application.
While trying to execute it I am getting NoSuch bean defined exception even though I have defined particular bean in config.
Here are my files:
#config.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="reportService" class="com.nagesh.sample.ReportServie"/>
</beans>
object class
`package com.nagesh.sample;
public class ReportService {
public void display() {
System.out.println("Hi, Welcome to Report Generation application");
}
}
main class file
package com.nagesh.spring.Sample;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.nagesh.sample.ReportService;
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
ApplicationContext context =
new ClassPathXmlApplicationContext("classpath*:config.xml");
ReportService reportService =
(ReportService) context.getBean("reportService");
reportService.display();
}
}`
here is pom.xml file
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.nagesh.spring</groupId>
<artifactId>Sample</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Sample</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.1.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.1.5.RELEASE</version>
</dependency>
</dependencies>
</project>`
How can I resolve this?
Upvotes: 0
Views: 92
Reputation: 16459
One Error :
<bean id="reportService" class="com.nagesh.sample.ReportServie"/>
changed it to
<bean id="reportService" class="com.nagesh.sample.ReportService"/>
Job Done :)
Upvotes: 1