error implementing spring social facebook - java

I'm trying to implement spring social facebook in my project but it's not working.
I followed this tutorial https://spring.io/guides/gs/accessing-facebook/
I get my app id and secret code.
my controller :
#Controller
#RequestMapping("/")
public class LoginController {
#Autowired
IUserService userService = null;
private Facebook facebook;
#Inject
public LoginController(Facebook facebook) {
this.facebook = facebook;
}
#RequestMapping(method = RequestMethod.GET)
public String display(Model model) {
Quote quote = userService.getTest();
System.out.println("type = " + quote.getType());
System.out.println("id of the code is " + quote.getValue().getId());
System.out.println("the quote = " + quote.getValue().getQuote());
if (!facebook.isAuthorized()) {
return "redirect:/connect/facebook";
}
model.addAttribute(facebook.userOperations().getUserProfile());
PagedList<Post> homeFeed = facebook.feedOperations().getHomeFeed();
model.addAttribute("feed", homeFeed);
return WebConstant.HOME_VIEW;
}
#RequestMapping(value = "/login", method = RequestMethod.GET)
public String loginPage() {
return WebConstant.LOGIN_VIEW;
}
}
And I get the following error :
HTTP Status 500- Servlet exception threw an exception
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'loginController' defined in file [C:\Users\Jérome\Documents\workspace-sts-3.7.1.RELEASE\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\Meltum\WEB-INF\classes\com\meltum\controller\LoginController.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [org.springframework.social.facebook.api.Facebook]: : No qualifying bean of type [org.springframework.social.facebook.api.Facebook] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.social.facebook.api.Facebook] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749)
org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:185)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1143)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1046)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:835)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:667)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:633)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:681)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:552)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:493)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
javax.servlet.GenericServlet.init(GenericServlet.java:158)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Unknown Source)
cause mère
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.social.facebook.api.Facebook] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373)
org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119)
org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014)
org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:813)
org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741)
org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:185)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1143)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1046)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:835)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:667)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:633)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:681)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:552)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:493)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
javax.servlet.GenericServlet.init(GenericServlet.java:158)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:673)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Unknown Source)
servlet-dispatcher.xml :
<beans>
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles-def.xml</value>
</list>
</property>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView"/>
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="messages"/>
</bean>
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>
<mvc:annotation-driven></mvc:annotation-driven>
Application.java :
#SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Does anybody has a solution ?

Related

java.lang.ClassNotFoundException: javax.validation.Validator

I am trying to add validation-api2.0.1.jar in my legacy project which is dependent upon jars that I add. not using maven or gradle to manage it. I am getting this error trace while I use javax.validation.Validator by autowiring.
SEVERE: Servlet [controller] in web application [/safehand-web] threw load() exception
java.lang.ClassNotFoundException: javax.validation.Validator
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1291)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2583)
at java.lang.Class.getDeclaredFields(Class.java:1916)
at org.springframework.util.ReflectionUtils.getDeclaredFields(ReflectionUtils.java:713)
at org.springframework.util.ReflectionUtils.doWithLocalFields(ReflectionUtils.java:655)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.buildPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:418)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:397)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(PersistenceAnnotationBeanPostProcessor.java:333)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:935)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:518)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:775)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:668)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:634)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:682)
at
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:553)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:494)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
at javax.servlet.GenericServlet.init(GenericServlet.java:158)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1183)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1099)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:989)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4931)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5241)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1419)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1409)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
And this is the jar list that I am using,
D:\safehand_latest\safehand\web\common-libraries\annotations-api.jar
D:\safehand_latest\safehand\web\common-libraries\antcontrib.jar
D:\safehand_latest\safehand\web\common-libraries\antlr-2.7.7.jar
D:\safehand_latest\safehand\web\common-libraries\ant-web-tasks-1.0.jar
D:\safehand_latest\safehand\web\common-libraries\aopalliance-1.0.jar
D:\safehand_latest\safehand\web\common-libraries\apache-commons-lang.jar
D:\safehand_latest\safehand\web\common-libraries\asm-3.1.jar
D:\safehand_latest\safehand\web\common-libraries\aspectjrt.jar
D:\safehand_latest\safehand\web\common-libraries\aspectjweaver.jar
D:\safehand_latest\safehand\web\common-libraries\avalon-framework-4.2.0.jar
D:\safehand_latest\safehand\web\common-libraries\barcode4j-fop-ext-complete.jar
D:\safehand_latest\safehand\web\common-libraries\batik-all-1.7.jar
D:\safehand_latest\safehand\web\common-libraries\bsh-core-2.0b4.jar
D:\safehand_latest\safehand\web\common-libraries\byte-buddy-1.8.12.jar
D:\safehand_latest\safehand\web\common-libraries\cglib-nodep-2.2.3.jar
D:\safehand_latest\safehand\web\common-libraries\classmate-1.3.4.jar
D:\safehand_latest\safehand\web\common-libraries\cloning-1.7.4.jar
D:\safehand_latest\safehand\web\common-libraries\com.sun.jersey.jersey-core-1.4.0.jar
D:\safehand_latest\safehand\web\common-libraries\commons-beanutils-1.8.3.jar
D:\safehand_latest\safehand\web\common-libraries\commons-cli-1.1.jar
D:\safehand_latest\safehand\web\common-libraries\commons-codec-1.8.jar
D:\safehand_latest\safehand\web\common-libraries\commons-collections-3.1.jar
D:\safehand_latest\safehand\web\common-libraries\commons-dbcp-1.4.jar
D:\safehand_latest\safehand\web\common-libraries\commons-digester-1.8.1.jar
D:\safehand_latest\safehand\web\common-libraries\commons-fileupload-1.3.1.jar
D:\safehand_latest\safehand\web\common-libraries\commons-io-2.4.jar
D:\safehand_latest\safehand\web\common-libraries\commons-lang3-3.1.jar
D:\safehand_latest\safehand\web\common-libraries\commons-logging-1.2.jar
D:\safehand_latest\safehand\web\common-libraries\commons-pool-1.4.jar
D:\safehand_latest\safehand\web\common-libraries\dom4j-1.6.1.jar
D:\safehand_latest\safehand\web\common-libraries\dynamicreports-core-4.0.0.jar
D:\safehand_latest\safehand\web\common-libraries\ecj-4.4.2.jar
D:\safehand_latest\safehand\web\common-libraries\ehcache-3.3.1.jar
D:\safehand_latest\safehand\web\common-libraries\el-api.jar
D:\safehand_latest\safehand\web\common-libraries\elasticsearch-6.1.4.jar
D:\safehand_latest\safehand\web\common-libraries\elasticsearch-rest-client-6.2.3.jar
D:\safehand_latest\safehand\web\common-libraries\elasticsearch-rest-high-level-client-6.2.3.jar
D:\safehand_latest\safehand\web\common-libraries\fop.jar
D:\safehand_latest\safehand\web\common-libraries\freemarker.jar
D:\safehand_latest\safehand\web\common-libraries\genson-1.3.jar
D:\safehand_latest\safehand\web\common-libraries\gnu-crypto.jar
D:\safehand_latest\safehand\web\common-libraries\groovy-all-2.0.1.jar
D:\safehand_latest\safehand\web\common-libraries\gson-2.2.4.jar
D:\safehand_latest\safehand\web\common-libraries\hamcrest-core-1.3.jar
D:\safehand_latest\safehand\web\common-libraries\hamcrest-library-1.3.jar
D:\safehand_latest\safehand\web\common-libraries\hamcrest-unit-test-1.3.jar
D:\safehand_latest\safehand\web\common-libraries\hibernate-commons-annotations-5.0.4.Final.jar
D:\safehand_latest\safehand\web\common-libraries\hibernate-core-5.3.2.Final.jar
D:\safehand_latest\safehand\web\common-libraries\hppc-0.7.3.jar
D:\safehand_latest\safehand\web\common-libraries\htmlcompressor-1.5.3.jar
D:\safehand_latest\safehand\web\common-libraries\httpasyncclient-4.1.3.jar
D:\safehand_latest\safehand\web\common-libraries\httpclient-4.5.5.jar
D:\safehand_latest\safehand\web\common-libraries\httpcore-4.4.9.jar
D:\safehand_latest\safehand\web\common-libraries\httpcore-nio-4.4.9.jar
D:\safehand_latest\safehand\web\common-libraries\httpmime-4.2.3.jar
D:\safehand_latest\safehand\web\common-libraries\iText-2.1.7.jar
D:\safehand_latest\safehand\web\common-libraries\itextpdf-5.5.4.jar
D:\safehand_latest\safehand\web\common-libraries\itext-pdfa-5.5.4.jar
D:\safehand_latest\safehand\web\common-libraries\itext-xtra-5.5.4.jar
D:\safehand_latest\safehand\web\common-libraries\jackson-annotations-2.7.0.jar
D:\safehand_latest\safehand\web\common-libraries\jackson-core-2.7.5.jar
D:\safehand_latest\safehand\web\common-libraries\jackson-core-asl-1.9.2.jar
D:\safehand_latest\safehand\web\common-libraries\jackson-databind-2.7.5.jar
D:\safehand_latest\safehand\web\common-libraries\jackson-datatype-hibernate4-2.4.1.jar
D:\safehand_latest\safehand\web\common-libraries\jackson-jaxrs-1.9.2.jar
D:\safehand_latest\safehand\web\common-libraries\jackson-mapper-asl-1.9.2.jar
D:\safehand_latest\safehand\web\common-libraries\jandex-2.0.5.Final.jar
D:\safehand_latest\safehand\web\common-libraries\jasperreports-6.0.0.jar
D:\safehand_latest\safehand\web\common-libraries\java-json.jar
D:\safehand_latest\safehand\web\common-libraries\javassist-3.22.0-GA.jar
D:\safehand_latest\safehand\web\common-libraries\javax.activation-api-1.2.0.jar
D:\safehand_latest\safehand\web\common-libraries\javax.persistence-api-2.2.jar
D:\safehand_latest\safehand\web\common-libraries\jaxb-api.jar
D:\safehand_latest\safehand\web\common-libraries\jaxb-core.jar
D:\safehand_latest\safehand\web\common-libraries\jaxb-impl.jar
D:\safehand_latest\safehand\web\common-libraries\jboss-logging-3.3.2.Final.jar
D:\safehand_latest\safehand\web\common-libraries\jboss-transaction-api_1.2_spec-1.1.1.Final.jar
D:\safehand_latest\safehand\web\common-libraries\jdom-1.0.jar
D:\safehand_latest\safehand\web\common-libraries\jersey-apache-client-1.6.jar
D:\safehand_latest\safehand\web\common-libraries\jersey-bundle-1.5.jar
D:\safehand_latest\safehand\web\common-libraries\jersey-client.jar
D:\safehand_latest\safehand\web\common-libraries\jersey-core-1.10.jar
D:\safehand_latest\safehand\web\common-libraries\jersey-json-1.19.jar
D:\safehand_latest\safehand\web\common-libraries\jersey-server-1.10.jar
D:\safehand_latest\safehand\web\common-libraries\jersey-servlet-1.10.jar
D:\safehand_latest\safehand\web\common-libraries\jersey-spring-1.1.5.jar
D:\safehand_latest\safehand\web\common-libraries\jmimemagic-0.1.0.jar
D:\safehand_latest\safehand\web\common-libraries\jmock-2.6.0.jar
D:\safehand_latest\safehand\web\common-libraries\jmock-junit3-2.6.0.jar
D:\safehand_latest\safehand\web\common-libraries\jmock-junit4-2.6.0.jar
D:\safehand_latest\safehand\web\common-libraries\jmock-legacy-2.6.0.jar
D:\safehand_latest\safehand\web\common-libraries\jmock-script-2.6.0.jar
D:\safehand_latest\safehand\web\common-libraries\joda-time-2.5.jar
D:\safehand_latest\safehand\web\common-libraries\json-simple-1.1.jar
D:\safehand_latest\safehand\web\common-libraries\jsp-api.jar
D:\safehand_latest\safehand\web\common-libraries\jsr311-api-1.0.jar
D:\safehand_latest\safehand\web\common-libraries\jstl.jar
D:\safehand_latest\safehand\web\common-libraries\jstl-1.2.jar
D:\safehand_latest\safehand\web\common-libraries\jta-1.1.jar
D:\safehand_latest\safehand\web\common-libraries\jtidy-r938.jar
D:\safehand_latest\safehand\web\common-libraries\junit-4.11.jar
D:\safehand_latest\safehand\web\common-libraries\log4j-1.2.17.jar
D:\safehand_latest\safehand\web\common-libraries\log4j-api-2.3.jar
D:\safehand_latest\safehand\web\common-libraries\log4j-core-2.3.jar
D:\safehand_latest\safehand\web\common-libraries\log4j-iostreams-2.3.jar
D:\safehand_latest\safehand\web\common-libraries\log4j-web-2.3.jar
D:\safehand_latest\safehand\web\common-libraries\lucene-analyzers-common-7.2.1.jar
D:\safehand_latest\safehand\web\common-libraries\lucene-core-7.2.1.jar
D:\safehand_latest\safehand\web\common-libraries\lucene-highlighter-7.2.1.jar
D:\safehand_latest\safehand\web\common-libraries\lucene-join-7.2.1.jar
D:\safehand_latest\safehand\web\common-libraries\lucene-memory-7.2.1.jar
D:\safehand_latest\safehand\web\common-libraries\lucene-queries-7.2.1.jar
D:\safehand_latest\safehand\web\common-libraries\lucene-queryparser-7.2.1.jar
D:\safehand_latest\safehand\web\common-libraries\lucene-sandbox-7.2.1.jar
D:\safehand_latest\safehand\web\common-libraries\mail-1.4.jar
D:\safehand_latest\safehand\web\common-libraries\mssql-jdbc-6.2.2.jre8.jar
D:\safehand_latest\safehand\web\common-libraries\mysql-connector-java-5.1.6-bin.jar
D:\safehand_latest\safehand\web\common-libraries\objenesis-1.0.jar
D:\safehand_latest\safehand\web\common-libraries\opencsv-2.3.jar
D:\safehand_latest\safehand\web\common-libraries\org.eclipse.paho.client.mqttv3-1.1.0.jar
D:\safehand_latest\safehand\web\common-libraries\org.json.jar
D:\safehand_latest\safehand\web\common-libraries\pdfbox-app-1.8.4.jar
D:\safehand_latest\safehand\web\common-libraries\poi-3.9.jar
D:\safehand_latest\safehand\web\common-libraries\poi-ooxml-3.8-20120326.jar
D:\safehand_latest\safehand\web\common-libraries\poi-ooxml-schemas-3.8-20120326.jar
D:\safehand_latest\safehand\web\common-libraries\quartz-2.2.3.jar
D:\safehand_latest\safehand\web\common-libraries\quartz-jobs-2.2.3.jar
D:\safehand_latest\safehand\web\common-libraries\quick-json-1.0.2.3.jar
D:\safehand_latest\safehand\web\common-libraries\serializer-2.7.1.jar
D:\safehand_latest\safehand\web\common-libraries\servlet-api.jar
D:\safehand_latest\safehand\web\common-libraries\slf4j-api-1.7.7.jar
D:\safehand_latest\safehand\web\common-libraries\slf4j-log4j12-1.7.7.jar
D:\safehand_latest\safehand\web\common-libraries\smslib-3.5.4.jar
D:\safehand_latest\safehand\web\common-libraries\spring-aop-4.3.1.RELEASE.jar
D:\safehand_latest\safehand\web\common-libraries\spring-aspects-3.2.4.RELEASE.jar
D:\safehand_latest\safehand\web\common-libraries\spring-beans-4.3.1.RELEASE.jar
D:\safehand_latest\safehand\web\common-libraries\spring-context-4.3.1.RELEASE.jar
D:\safehand_latest\safehand\web\common-libraries\spring-context-support-4.1.7.RELEASE.jar
D:\safehand_latest\safehand\web\common-libraries\spring-core-4.3.1.RELEASE.jar
D:\safehand_latest\safehand\web\common-libraries\spring-data-redis-1.0.1.jar
D:\safehand_latest\safehand\web\common-libraries\spring-expression-4.3.1.RELEASE.jar
D:\safehand_latest\safehand\web\common-libraries\spring-instrument-3.2.4.RELEASE.jar
D:\safehand_latest\safehand\web\common-libraries\spring-instrument-tomcat-3.2.4.RELEASE.jar
D:\safehand_latest\safehand\web\common-libraries\spring-jdbc-4.2.2.RELEASE.jar
D:\safehand_latest\safehand\web\common-libraries\spring-orm-4.3.1.RELEASE.jar
D:\safehand_latest\safehand\web\common-libraries\spring-oxm-4.3.1.RELEASE.jar
D:\safehand_latest\safehand\web\common-libraries\spring-security-config-4.0.1.RELEASE.jar
D:\safehand_latest\safehand\web\common-libraries\spring-security-core-4.0.1.RELEASE.jar
D:\safehand_latest\safehand\web\common-libraries\spring-security-core-tiger-2.0.8.RELEASE.jar
D:\safehand_latest\safehand\web\common-libraries\spring-security-crypto-3.2.4.RELEASE.jar
D:\safehand_latest\safehand\web\common-libraries\spring-security-javaconfig-1.0.0.CI-20130808.110017-278.jar
D:\safehand_latest\safehand\web\common-libraries\spring-security-taglibs-3.2.4.RELEASE.jar
D:\safehand_latest\safehand\web\common-libraries\spring-security-web-4.1.1.RELEASE.jar
D:\safehand_latest\safehand\web\common-libraries\spring-session-1.3.1.RELEASE.jar
D:\safehand_latest\safehand\web\common-libraries\spring-test-3.2.4.RELEASE.jar
D:\safehand_latest\safehand\web\common-libraries\spring-tx-4.2.2.RELEASE.jar
D:\safehand_latest\safehand\web\common-libraries\spring-web-4.3.1.RELEASE.jar
D:\safehand_latest\safehand\web\common-libraries\spring-webmvc-4.3.1.RELEASE.jar
D:\safehand_latest\safehand\web\common-libraries\spring-webmvc-portlet-3.2.4.RELEASE.jar
D:\safehand_latest\safehand\web\common-libraries\spring-ws-core-2.2.0.RELEASE.jar
D:\safehand_latest\safehand\web\common-libraries\spring-xml-2.0.3.RELEASE.jar
D:\safehand_latest\safehand\web\common-libraries\sqljdbc4.jar
D:\safehand_latest\safehand\web\common-libraries\sqljdbc41.jar
D:\safehand_latest\safehand\web\common-libraries\standard.jar
D:\safehand_latest\safehand\web\common-libraries\stripe-java-3.9.0.jar
D:\safehand_latest\safehand\web\common-libraries\super-csv-2.0.0-sources.jar
D:\safehand_latest\safehand\web\common-libraries\UserAgentUtils-1.14.jar
D:\safehand_latest\safehand\web\common-libraries\xml-apis-1.3.04.jar
D:\safehand_latest\safehand\web\common-libraries\xmlbeans-2.3.0.jar
D:\safehand_latest\safehand\web\common-libraries\xmlgraphics-commons-1.5.jar
D:\safehand_latest\safehand\web\common-libraries\yuicompressor-2.4.2.jar
D:\safehand_latest\safehand\web\common-libraries\ziputils-1.1.jar
D:\safehand_latest\safehand\web\common-libraries\zxing-2.1.jar
D:\safehand_latest\safehand\web\common-libraries\zxing-j2se-1.7.jar
D:\documents\Jars\all validation jar\validation-api-2.0.1.Final.jar
I dont know what is wrong and and why i cannot use my validation-api-2.0.1.Final.jar. Any help or suggestion?
It says exactly what your issue is.
"java.lang.ClassNotFoundException: javax.validation.Validator"
It cannot load the library for any reason.
Try to readd the library or try to find an another download.

Spring batch configuration

I have a problem with spring batch and spring boot
Here is my jobs.xml
<!-- stored job-meta in database -->
<bean id="jobRepository"
class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
<property name="transactionManager" ref="jobTransactionManager" />
</bean>
<bean id="jobLauncher"
class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository" />
</bean>
<bean id="dummyTask" class="ch.autexis.DummyTask"/>
<!-- define a job with multiple tasks/steps -->
<batch:job id="MESaaSConnectorJob" restartable="true">
<batch:step id="job_1" allow-start-if-complete="true">
<tasklet ref="dummyTask" />
</batch:step>
</batch:job>
<!-- runner executes the job -->
<bean id="MESaaS_sensor_runner" class="ch.autexis.RunScheduler">
<property name="job" ref="MESaaSConnectorJob" />
<property name="launcher" ref="jobLauncher" />
</bean>
Here is my Runscheduler:
#Component
public class RunScheduler {
private JobLauncher launcher;
private Job job;
public void run() {
try {
String dateParam = new Date().toString();
JobParameters param =
new JobParametersBuilder().addString("date", dateParam).toJobParameters();
System.out.println(dateParam);
JobExecution execution = launcher.run(job, param);
long duration = execution.getEndTime().getTime() - execution.getStartTime().getTime();
System.out.println("Job:" + job.getName() + " ended with status " + execution.getStatus().toString()
+ " and duration of " + duration + "ms");
} catch (Exception e) {
e.printStackTrace();
}
}
public JobLauncher getLauncher() {
return launcher;
}
public void setLauncher(JobLauncher launcher) {
this.launcher = launcher;
}
public Job getJob() {
return job;
}
public void setJob(Job job) {
this.job = job;
}
}
Here is the DummyTask:
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
import org.springframework.batch.core.step.tasklet.Tasklet;
import org.springframework.batch.repeat.RepeatStatus;
public class DummyTask implements Tasklet {
#Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception {
System.out.println("Dummy - Task executed");
return RepeatStatus.FINISHED;
}
}
And here is my stacktrace:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'jobOperator' defined in class path resource [org/springframework/boot/autoconfigure/batch/BatchAutoConfiguration.class]: Unsatisfied dependency expressed through constructor argument with index 2 of type [org.springframework.batch.core.configuration.ListableJobLocator]: No qualifying bean of type [org.springframework.batch.core.configuration.ListableJobLocator] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.batch.core.configuration.ListableJobLocator] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:749) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:464) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:839) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538) ~[spring-context-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1191) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1180) [spring-boot-1.3.3.RELEASE.jar:1.3.3.RELEASE]
at ch.autexis.BatchApplication.main(BatchApplication.java:26) [classes/:na]
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.batch.core.configuration.ListableJobLocator] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1373) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1119) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:813) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:741) ~[spring-beans-4.2.5.RELEASE.jar:4.2.5.RELEASE]
... 18 common frames omitted
Do you have any idea why the jobOperator bean can not be created?
Thanks for help
Use the following annotation on your Application class to read the xml config:
#SpringBootApplication
#ImportResource("applicationContext.xml")
Spring can find job in its context.You have to use bean id as qualifier and inject it into your Class. You have to autowire your Job like
#Autowired
#Qualifier("MESaaSConnectorJob")
private Job job;
For jobLauncher it will take by default spring bean name convention.For example JobLauncher to jobLauncher.You don't need any #Qualifier for that.

Cannot use Components/Service/Repository in Controller class

I have a well configurated dao layer(I've created test to check it), and now I would like to integrate my project with spring mvc.
I've added this configuration:
#Configuration
#EnableWebMvc
#ComponentScan(basePackages = "com.szymon.controller")
public class WebMvcConfig {
#Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setViewClass(JstlView.class);
viewResolver.setPrefix("/WEB-INF/views/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
}
public class WebInitializer implements WebApplicationInitializer {
public void onStartup(ServletContext container) throws ServletException {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.register(WebMvcConfig.class);
ctx.setServletContext(container);
ServletRegistration.Dynamic servlet = container.addServlet("dispatcher", new DispatcherServlet(ctx));
servlet.setLoadOnStartup(1);
servlet.addMapping("/");
}
}
And my controller looks like:
#Controller
public class HelloWorldController {
#Autowired
private MeetingRepository meetingRepository;
#RequestMapping("/hello")
public String helloWorld(Model model) {
model.addAttribute("message", "message");
model.addAttribute("meeting", meetingRepository.findOne(1L));
return "helloWorld";
}
#RequestMapping("/hel")
public String hel(Model model) {
model.addAttribute("message", "message");
return "helloWorld2";
}
}
After commenting meetingRepository field and helloWorld() method servlet works fine. But if its not commented it doesn't working:
javax.servlet.ServletException: Servlet.init() for servlet dispatcher threw exception
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2500)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2489)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)
root cause
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'helloWorldController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.szymon.repository.MeetingRepository com.szymon.controller.HelloWorldController.meetingRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.szymon.repository.MeetingRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1208)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:762)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:664)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:536)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:490)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
javax.servlet.GenericServlet.init(GenericServlet.java:158)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2500)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2489)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)
root cause
org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.szymon.repository.MeetingRepository com.szymon.controller.HelloWorldController.meetingRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.szymon.repository.MeetingRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1208)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:762)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:664)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:536)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:490)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
javax.servlet.GenericServlet.init(GenericServlet.java:158)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2500)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2489)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)
root cause
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.szymon.repository.MeetingRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1301)
org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1047)
org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:942)
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:533)
org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1208)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:755)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:762)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:664)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:536)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:490)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
javax.servlet.GenericServlet.init(GenericServlet.java:158)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2500)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2489)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)
It looks, that spring is not making beans when using spring mvc. How should i configure my application for working properly?
EDIT
MeetingRepository class:
public interface MeetingRepository extends JpaRepository<Meeting, Long> {
}
#Configuration
#EnableJpaRepositories(basePackages = "com.szymon.repository")
#EnableTransactionManagement
public class DataAccessConfig {
#Bean
public LocalEntityManagerFactoryBean entityManagerFactory() {
LocalEntityManagerFactoryBean localEntityManagerFactoryBean = new LocalEntityManagerFactoryBean();
localEntityManagerFactoryBean.setPersistenceUnitName("postgres");
return localEntityManagerFactoryBean;
}
#Bean
public JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
JpaTransactionManager jpaTransactionManager = new JpaTransactionManager();
jpaTransactionManager.setEntityManagerFactory(entityManagerFactory);
return jpaTransactionManager;
}
}
It's working well, because I've tested it:
#RunWith(SpringJUnit4ClassRunner.class)
#ContextConfiguration(classes = DataAccessConfig.class)
public class MeetingRepositoryTest {
#Autowired
private MeetingRepository meetingRepository;
#Test
public void test() {
Meeting meeting = new Meeting();
meeting.setAddedDate(new Date());
meeting.setMeetingDate(new Date(System.currentTimeMillis() + 604800000));
meeting.setNotes("Moje pierwsze spotkanie.");
meeting.setPlace("Pokoj 200");
meetingRepository.save(meeting);
Assert.assertTrue(true);
}
}
Try placing #EnableTransactionManagement and #EnableJpaRepositories(basePackages=...) on the WebMvcConfig.java class and place #Repository on the MeetingRepository class.
Although DataAccessConfig class is marked as #Configuration it is not being referenced in your WebInitializer class. The WebInitializer class is only referencing WebMvcConfig and so only that is considered.
If you want you can specify DataAccessConfig along with WebMvcConfig using ctx.register(WebMvcConfig.class, DataAccessConfig.class);. That should work as well.
Mark your Repository interface like this
#Repository
public interface MeetingRepository extends JpaRepository<Meeting, Long> {
}

Unable to Autowire ServiceImpl Class Bean with Service Class Object

The error which I'm facing is as follows:
root cause
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginAndSignUpController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.frosters.firststep.service.LoginAndSignUpService com.frosters.firststep.controller.LoginAndSignUpController.loginAndSignUpService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.frosters.firststep.service.LoginAndSignUpService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:834)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:667)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:633)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:681)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:552)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:493)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
javax.servlet.GenericServlet.init(GenericServlet.java:158)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)
root cause
org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.frosters.firststep.service.LoginAndSignUpService com.frosters.firststep.controller.LoginAndSignUpController.loginAndSignUpService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.frosters.firststep.service.LoginAndSignUpService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:571)
org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:834)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:667)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:633)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:681)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:552)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:493)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
javax.servlet.GenericServlet.init(GenericServlet.java:158)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)
root cause
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.frosters.firststep.service.LoginAndSignUpService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {#org.springframework.beans.factory.annotation.Autowired(required=true)}
org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1326)
org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1072)
org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:967)
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:543)
org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)
org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1214)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:543)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:772)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:834)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537)
org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:667)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:633)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:681)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:552)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:493)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
javax.servlet.GenericServlet.init(GenericServlet.java:158)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:625)
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Thread.java:745)
I've tried resolving it through using #Component,#Service annotations and has tried defining the bean in XML Configuration as explained in other StackOverflow links but I'm getting the same error. May be I'm not getting it right or I'm doing something wrong.
ControllerClass is as follows:
package com.frosters.firststep.controller;
#RequestMapping(value="/login.html")
#Controller
public class LoginAndSignUpController {
#Autowired
private LoginAndSignUpService loginAndSignUpService;
#ModelAttribute("userVO")
public UserVO createUserVOBean(){
return new UserVO();
}
#RequestMapping(method=RequestMethod.GET)
public ModelAndView getLoginForm(){
System.out.println("inside getLoginForm() method");
return new ModelAndView("Login");
}
#RequestMapping(method=RequestMethod.POST)
public ModelAndView verifyLogin(#ModelAttribute("userVO")UserVO userVO){
System.out.println("inside verifyLogin");
boolean result = loginAndSignUpService.verifyUser(userVO);
ModelAndView model;
if(!result){
model = new ModelAndView("Login");
model.addObject("loginError", "invalid username/password");
}
else
model = new ModelAndView("LoginSuccess"); //temporary view
return model;
}
}
ServiceImplClass is as follows:
package com.frosters.firststep.serviceimpl;
public class LoginAndSignUpServiceImpl implements LoginAndSignUpService{
#Autowired
private LoginAndSignUpDAO loginAndSignUpDAO;
public boolean verifyUser(UserVO userVO) {
boolean result = loginAndSignUpDAO.validateUser(userVO);
if(result)
return true;
else
return false;
}
}
DAOImpl Class is as follows:
package com.frosters.firststep.daoimpl;
public class LoginAndSignUpDAOImpl extends NamedParameterJdbcDaoSupport implements LoginAndSignUpDAO{
public boolean validateUser(UserVO userVO) {
String userName = userVO.getUserName();
String password = userVO.getPassword();
SqlParameterSource paramSource = new MapSqlParameterSource("username", userName);
try{
String pass = this.getNamedParameterJdbcTemplate().queryForObject(FSUtils.LOGIN_INFO, paramSource, String.class);
if(pass != null && !pass.isEmpty()){
if(pass.equals(password))
return true;
else
return false;
}
else
return false;
}catch(EmptyResultDataAccessException ex){
return false;
}
}
}
web.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID"
version="3.0">
<display-name>Login And SignUp</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/applicationContext.xml</param-value>
</context-param>
<servlet>
<servlet-name>spring-dispatcher-servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/spring-dispatcher-servlet.xml</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>spring-dispatcher-servlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
spring-dispatcher-servlet.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"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd">
<context:component-scan base-package="com.frosters.firststep" />
<mvc:annotation-driven />
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
applicationContext.xml where I've defined the beans:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.2.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-4.2.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.2.xsd">
<context:property-placeholder location="classpath:DbUtil.properties"/>
<!-- <context:component-scan base-package="com.frosters.firststep" />
<mvc:annotation-driven /> -->
<bean name="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.mysql.driverClassName}" />
<property name="url" value="${jdbc.mysql.url}" />
<property name="username" value="${jdbc.mysql.username}" />
<property name="password" value="${jdbc.mysql.password}" />
</bean>
<bean id="loginAndSignUpDAO" class="com.frosters.firststep.daoimpl.LoginAndSignUpDAOImpl">
<property name="dataSource" ref="dataSource" />
</bean>
<bean id="loginAndSignUpService" class="com.frosters.firststep.serviceimpl.LoginAndSignUpServiceImpl" />
</beans>
I've tried defining all the beans in spring-dispatcher-servlet.xml also but doing this also doesn't resolve the problem.
someone can please help me to see where the fault? .... Thank you ...
add ContextCLoaderListener in your web.xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
The line:
<context:component-scan base-package="com.frosters.firststep" />
Should be in applicationContext.xml and not in the spring-dispatcher-servlet.xml.
The Spring component scan, will scan your base package for all beans that are annotated with
#Repository (for DAO)
#Component
#Service (for Service)
#Controller (for Controller)
Since Spring do not find any annotation for DAOImpl and ServiceImpl, hence it dose not initialize them as a consequences your #Autowired does not work because there are no qualifying candidates.
So add #Repository to your DaoImpl and #Service to your ServiceImpl classes and then try again.
package com.frosters.firststep.serviceimpl;
#Service
public class LoginAndSignUpServiceImpl implements LoginAndSignUpService{
#Autowired
private LoginAndSignUpDAO loginAndSignUpDAO;
public boolean verifyUser(UserVO userVO) {
boolean result = loginAndSignUpDAO.validateUser(userVO);
if(result)
return true;
else
return false;
}
}
and
package com.frosters.firststep.daoimpl;
#Repository
public class LoginAndSignUpDAOImpl extends NamedParameterJdbcDaoSupport implements LoginAndSignUpDAO{
public boolean validateUser(UserVO userVO) {
String userName = userVO.getUserName();
String password = userVO.getPassword();
SqlParameterSource paramSource = new MapSqlParameterSource("username", userName);
try{
String pass = this.getNamedParameterJdbcTemplate().queryForObject(FSUtils.LOGIN_INFO, paramSource, String.class);
if(pass != null && !pass.isEmpty()){
if(pass.equals(password))
return true;
else
return false;
}
else
return false;
}catch(EmptyResultDataAccessException ex){
return false;
}
}
}
Try the following order
<mvc:annotation-driven />
<context:annotation-config />
<context:component-scan base-package="com.frosters.firststep" />
or
<mvc:annotation-driven />
<context:annotation-config />
<context:component-scan base-package="com.frosters.*" />
As Imran indicated in his post (which could be the main cause), put the context listener to your web.xml
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name

I'm running Tomcat and everything seems to work fine until I actually try bringing up the page in Postman, then I get this error (full stack trace):
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'stopController' defined in file [C:\Users\Scott Meyer\metrolink-project\target\classes\metrolink\rest\mvc\StopController.class]: Unsatisfied dependency expressed through constructor argument with index 0 of type [metrolink.core.services.StopService]: : No qualifying bean of type [metrolink.core.services.StopService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [metrolink.core.services.StopService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:751)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:185)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1133)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1036)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:505)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:725)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
at javax.servlet.GenericServlet.init(GenericServlet.java:160)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:865)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:136)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:744)
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [metrolink.core.services.StopService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1261)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1009)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:904)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:815)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:743)
... 36 more
Dec 03, 2014 1:42:13 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet mvc-dispatcher
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [metrolink.core.services.StopService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1261)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1009)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:904)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:815)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:743)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:185)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1133)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1036)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:505)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:725)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:658)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:624)
at org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:672)
at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:543)
at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484)
at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
at javax.servlet.GenericServlet.init(GenericServlet.java:160)
at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1280)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1193)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:865)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:136)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:744)
Here's my business-config File:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:component-scan base-package="metrolink.core.repositories.jpa"/>
<bean id="dataSource" class="org.apache.commons.dbcp2.BasicDataSource">
<property name="driverClassName" value="org.sqlite.JDBC" />
<property name="url" value="jdbc:sqlite:metrolink.db" />
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
</property>
<property name="jpaProperties">
<map>
<entry key="hibernate.hbm2ddl.auto" value="create-drop"/>
<entry key="hibernate.show_sql" value="true"/>
<entry key="hibernate.dialect" value="org.hibernate.dialect.SQLiteDialect" />
<entry key="hibernate.current_session_context_class" value="thread" />
</map>
</property>
<property name="packagesToScan" value="metrolink.core.entities"/>
</bean>
<tx:annotation-driven/>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"/>
<context:component-scan base-package="metrolink.core.services" />
</beans>
And the relevant code:
package metrolink.core.services.impl;
import etc...
#Service
#Transactional
public class StopServiceImpl implements StopService {
#Autowired
private StopRepo stopRepo;
#Override
public Stop find(int stopId) {
Stop stop = stopRepo.find(stopId);
if( stop == null ) {
throw new StopDoesNotExistException();
}
return stop;
}
#Override
public Stop findByStopName(String name) {
return stopRepo.findStopByName(name);
}
#Override
public StopList findAllStops() {
return new StopList (stopRepo.findAllStops());
}
}
and
package metrolink.rest.mvc;
import etc...
#Controller
#RequestMapping(value="/rest/stops")
public class StopController {
private StopService stopService;
#Autowired
public StopController(StopService stopService) {
this.stopService = stopService;
}
#RequestMapping(method= RequestMethod.GET)
public ResponseEntity<StopListResource> findAllStops(#RequestParam(value="name", required=false) String name) {
StopList list = null;
if(name == null) {
list = stopService.findAllStops();
} else {
Stop stop = stopService.findByStopName(name);
if(stop == null) {
list = new StopList(new ArrayList<Stop>());
} else {
list = new StopList(Arrays.asList(stop));
}
}
StopListResource res = new StopListResourceAsm().toResource(list);
return new ResponseEntity<StopListResource>(res, HttpStatus.OK);
}
#RequestMapping(value="/{stopId}", method= RequestMethod.GET)
public ResponseEntity<StopResource> getStop( #PathVariable int stopId ) {
Stop stop = stopService.find(stopId);
if(stop != null) {
StopResource res = new StopResourceAsm().toResource(stop);
return new ResponseEntity<StopResource>(res, HttpStatus.OK);
} else {
return new ResponseEntity<StopResource>(HttpStatus.NOT_FOUND);
}
}
#RequestMapping(method= RequestMethod.GET)
public ResponseEntity<StopListResource> findAllStops() {
StopList stopList = stopService.findAllStops();
StopListResource stopListRes = new StopListResourceAsm().toResource(stopList);
return new ResponseEntity<StopListResource>(stopListRes, HttpStatus.OK);
}
}
Here's my web.xml:
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring/business-config.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>mvc-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>mvc-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
Include only the following line. Remove all other context:component-scan entries.
<context:component-scan base-package="metrolink.core"/>

Categories