Reputation: 3
Error: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'issueTemplateServiceImpl': Unsatisfied dependency expressed through field 'repo'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.conseco.repository.IssueTemplateRepo' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:596) at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessProperties(AutowiredAnnotationBeanPostProcessor.java:374) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1395) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:592) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:849) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:400) at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:291) at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:103) at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4840) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5303) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1407) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1397) at java.base/java.util.concurrent.FutureTask.run(Unknown Source) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at java.base/java.lang.Thread.run(Unknown Source) Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.conseco.repository.IssueTemplateRepo' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1654) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1213) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1167) at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:593) ... 24 more
My code:
IssueTemplateController:
package com.conseco.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.conseco.dao.IssueTemplateInfo;
import com.conseco.service.IssueTemplateService;
@Controller
public class IssueTemplateController {
@Autowired
IssueTemplateService service;
@RequestMapping("/new")
public ModelAndView create()
{
System.out.println("service: "+service);
ModelAndView mav=new ModelAndView("index");
System.out.println("1..................");
IssueTemplateInfo issue=new IssueTemplateInfo();
issue.setSDT("123456");
issue.setAnalysis("test");
issue.setApplicaiton("AWD");
issue.setBatch("no");
issue.setBusinessImpact("N/A");
issue.setDescription("will describe later");
issue.setEMER("N/A");
issue.setImpDate("25th");
issue.setPermanentFix("TBT");
issue.setQCDefect("234");
issue.setRootCause("unknown");
issue.setSeverity(3);
issue.setStatus("Inprogress");
issue.setWorkAround("a lot to work on");
service.save(issue);
System.out.println("4..............");
return mav;
}
}
MyFrontController:
package com.conseco.controller;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
import com.conseo.config.WebMvcConfig;
public class MyFrontController extends AbstractAnnotationConfigDispatcherServletInitializer{
@Override
protected Class<?>[] getRootConfigClasses() {
// TODO Auto-generated method stub
return new Class[] {WebMvcConfig.class};
}
@Override
protected Class<?>[] getServletConfigClasses() {
// TODO Auto-generated method stub
return null;
}
@Override
protected String[] getServletMappings() {
// TODO Auto-generated method stub
return new String[] {"/"};
}
}
IssueTemplateRepo:
package com.conseco.repository;
import org.springframework.data.repository.CrudRepository;
import com.conseco.dao.IssueTemplateInfo;
public interface IssueTemplateRepo extends CrudRepository<IssueTemplateInfo, String> {
}
IssueTemplateService:
package com.conseco.service;
import org.springframework.stereotype.Service;
import com.conseco.dao.IssueTemplateInfo;
public interface IssueTemplateService {
IssueTemplateInfo save(IssueTemplateInfo issue);
}
IssueTemplateServiceImpl:
package com.conseco.service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.conseco.dao.IssueTemplateInfo;
import com.conseco.repository.IssueTemplateRepo;
@Service
public class IssueTemplateServiceImpl implements IssueTemplateService {
@Autowired
private IssueTemplateRepo repo;
public IssueTemplateRepo getRepo() {
return repo;
}
public void setRepo(IssueTemplateRepo repo) {
this.repo = repo;
}
@Override
public IssueTemplateInfo save(IssueTemplateInfo issue) {
// TODO Auto-generated method stub
return repo.save(issue);
}
}
WebMvcConfigurer:
package com.conseo.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
@EnableWebMvc
@ComponentScan({"com.conseco.service","com.conseco.controller","com.conseco.repository","com.conseco.dao"})
public class WebMvcConfig implements WebMvcConfigurer {
}
Upvotes: 0
Views: 1866
Reputation: 80904
Add the annotation @Component
on the interface:
@Component
public interface IssueTemplateRepo extends CrudRepository<IssueTemplateInfo, String> {
}
After you add the @Component
annotation will become a spring bean and it can be managed managed by the Spring IoC container.
Upvotes: 0