Integrating JSF, SPRING and Hibernate and always getting the...












-1















I'm new to Spring. Trying to build a Web project using JSF Spring and hibernate in Maven but seems my application is not able to get the spring configuration XML.



Below is the Stack Trace:



WARNING: Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl] for bean with name 'userDetailsService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1328)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:622)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:591)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1397)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:968)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:735)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4745)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5207)
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:748)
Caused by: java.lang.ClassNotFoundException: co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1291)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:249)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:395)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1349)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1320)
... 19 more

Nov 09, 2018 5:00:26 PM org.springframework.web.context.ContextLoader initWebApplicationContext
SEVERE: Context initialization failed
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl] for bean with name 'userDetailsService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1328)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:622)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:591)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1397)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:968)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:735)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4745)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5207)
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:748)
Caused by: java.lang.ClassNotFoundException: co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1291)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:249)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:395)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1349)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1320)
... 19 more

Nov 09, 2018 5:00:26 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class [org.springframework.web.context.ContextLoaderListener]
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl] for bean with name 'userDetailsService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1328)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:622)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:591)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1397)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:968)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:735)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4745)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5207)
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:748)
Caused by: java.lang.ClassNotFoundException: co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1291)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:249)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:395)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1349)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1320)
... 19 more

Nov 09, 2018 5:00:26 PM com.sun.faces.config.ConfigureListener contextInitialized
INFO: Initializing Mojarra 2.2.10 ( 20150205-0906 https://svn.java.net/svn/mojarra~svn/tags/2.2.10@14334) for context '/JSF_SPRING_HIBERNATE'
Nov 09, 2018 5:00:27 PM com.sun.faces.spi.InjectionProviderFactory createInstance
INFO: JSF1048: PostConstruct/PreDestroy annotations present. ManagedBeans methods marked with these annotations will have said annotations processed.
Nov 09, 2018 5:00:27 PM com.sun.faces.config.ConfigureListener$WebConfigResourceMonitor$Monitor <init>
INFO: Monitoring file:/C:/Users/x4180/workspace1/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/JSF_SPRING_HIBERNATE/WEB-INF/faces-config.xml for modifications
Nov 09, 2018 5:00:27 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: One or more listeners failed to start. Full details will be found in the appropriate container log file
Nov 09, 2018 5:00:27 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/JSF_SPRING_HIBERNATE] startup failed due to previous errors
Nov 09, 2018 5:00:27 PM org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
Nov 09, 2018 5:00:27 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc
WARNING: The web application [JSF_SPRING_HIBERNATE] registered the JDBC driver [com.microsoft.sqlserver.jdbc.SQLServerDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Nov 09, 2018 5:00:27 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
WARNING: The web application [JSF_SPRING_HIBERNATE] appears to have started a thread named [Mojarra-WebResourceMonitor-1-thread-1] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
sun.misc.Unsafe.compareAndSwapInt(Native Method)
java.util.concurrent.atomic.AtomicInteger.compareAndSet(AtomicInteger.java:133)
java.util.concurrent.ThreadPoolExecutor.compareAndDecrementWorkerCount(ThreadPoolExecutor.java:421)
java.util.concurrent.ThreadPoolExecutor.decrementWorkerCount(ThreadPoolExecutor.java:430)
java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1048)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:748)
Nov 09, 2018 5:00:27 PM org.apache.catalina.loader.WebappClassLoaderBase checkThreadLocalMapForLeaks
SEVERE: The web application [JSF_SPRING_HIBERNATE] created a ThreadLocal with key of type [com.microsoft.sqlserver.jdbc.ActivityCorrelator$1] (value [com.microsoft.sqlserver.jdbc.ActivityCorrelator$1@66507bd3]) and a value of type [com.microsoft.sqlserver.jdbc.ActivityId] (value [ce07abca-cce2-4b61-8d6a-65a51418366a-17]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Nov 09, 2018 5:00:27 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Nov 09, 2018 5:00:27 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Nov 09, 2018 5:00:27 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 27085 ms


POM.XML



<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>JSF_SPRING_HIBERNATE</groupId>
<artifactId>JSF_SPRING_HIBERNATE</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>JSF_SPRING_HIBERNATE Maven Webapp</name>
<url>http://maven.apache.org</url>


<properties>
<java.version>1.8</java.version>
<spring.version>4.1.6.RELEASE</spring.version>
<jsf2.version>2.2.10</jsf2.version>
<hibernate.version>4.3.8.Final</hibernate.version>
</properties>

<dependencies>
<!-- Spring and Transactions -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>

<!-- Spring ORM support -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>

<!-- JSF Dependencies -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>${jsf2.version}</version>
</dependency>

<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>${jsf2.version}</version>
</dependency>

<!-- hibernate 4 -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>

<!-- database pool -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.0</version>
</dependency>

<!-- sql server java connector -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.1.0.jre8</version>
</dependency>
</dependencies>
<build>
<finalName>JSF_SPRING_HIBERNATE</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>


WEB.XML



<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>


ApplicationContext.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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd">

<!-- support spring annotation -->
<context:annotation-config />
<!-- support annotation transaction -->
<tx:annotation-driven transaction-manager="transactionManager" />

<!-- declare datasource -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<property name="url" value="jdbc:sqlserver://CIS-GIASDBT2:3433;databaseName=PNXProjectBWrk;integratedSecurity=true" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>

<!--Hibernate session factory configuration -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- load hibernate configuration file -->
<property name="configLocation" value="/WEB-INF/hibernate.cfg.xml" />
<!-- where to find the ORM classes -->
<property name="packagesToScan" value="co.MyJavaCode.hibernate.model" />
</bean>

<!-- Transaction manager -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<!-- service -->
<bean id="userDetailsService" class="co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl" />

<!-- dao -->
<bean id="userDetailsDao" class="co.MyJavaCode.spring.dao.impl.UserDetailsDaoImpl" />

</beans>


faces-config.xml



**<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
<application>
<el-resolver>
org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver>
</application>
</faces-config>**


Click link :Package Structure
I'm stuck in the process and couldn't get what exactly I'm missing. Tried to do it in several way but didn't succeed. googled a lot but couldn't get the solution.



Please help!



UserDetailsServiceImpl.Java



package co.MyJavaCode.spring.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import co.MyJavaCode.hibernate.model.UserDetails;
import co.MyJavaCode.spring.dao.UserDetailsDao;
import co.MyJavaCode.spring.service.UserDetailsService;

@Component
public class UserDetailsServiceImpl implements UserDetailsService {

@Autowired
private UserDetailsDao userDetailsDao;

@Override
public UserDetails getuserDetails(int id) {
return userDetailsDao.getuserDetails(id);
}

@Override
public List<UserDetails> getAllUserDetails() {
return userDetailsDao.getAllUserDetails();
}

public UserDetailsDao getUserDetailsDao() {
return userDetailsDao;
}

}


UserDetailsDaoImpl.java



package co.MyJavaCode.spring.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import co.MyJavaCode.hibernate.model.UserDetails;
import co.MyJavaCode.spring.dao.UserDetailsDao;

@Component
public class UserDetailsDaoImpl implements UserDetailsDao {

@Autowired
private SessionFactory sessionFactory;

@Transactional
@Override
public UserDetails getuserDetails(int id) {
UserDetails userDetails = (UserDetails) sessionFactory.getCurrentSession().get(UserDetails.class, id);
return userDetails;
}

@Transactional
@Override
public List<UserDetails> getAllUserDetails() {

@SuppressWarnings("unchecked")
List<UserDetails> userDetails = (List<UserDetails>) sessionFactory.getCurrentSession()
.createCriteria(UserDetails.class).list();

//or below query

/*
* @SuppressWarnings("unchecked") List<UserDetails> userDetails =
* (List<UserDetails>)sessionFactory.getCurrentSession().createQuery(
* "from UserDetails").list();
*/
return userDetails;
}

public SessionFactory getSessionFactory() {
return sessionFactory;
}

}









share|improve this question

























  • Can you show me your package structure? Normally, this is a problem with the component scan.

    – Alain Cruz
    Nov 9 '18 at 22:16













  • Added the package structure

    – Sumantra Chakraborty
    Nov 12 '18 at 15:26











  • You added the @Component or @Service annotation to your classes, right?

    – Alain Cruz
    Nov 12 '18 at 18:22











  • I've added @Component in my UserDetailsServiceImpl.java and UserDetailsDaoImpl.java. Attached the code snippebts for both these classes.

    – Sumantra Chakraborty
    Nov 12 '18 at 22:32











  • Do you have any suggestion on this?

    – Sumantra Chakraborty
    Nov 14 '18 at 14:38
















-1















I'm new to Spring. Trying to build a Web project using JSF Spring and hibernate in Maven but seems my application is not able to get the spring configuration XML.



Below is the Stack Trace:



WARNING: Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl] for bean with name 'userDetailsService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1328)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:622)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:591)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1397)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:968)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:735)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4745)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5207)
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:748)
Caused by: java.lang.ClassNotFoundException: co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1291)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:249)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:395)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1349)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1320)
... 19 more

Nov 09, 2018 5:00:26 PM org.springframework.web.context.ContextLoader initWebApplicationContext
SEVERE: Context initialization failed
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl] for bean with name 'userDetailsService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1328)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:622)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:591)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1397)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:968)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:735)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4745)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5207)
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:748)
Caused by: java.lang.ClassNotFoundException: co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1291)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:249)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:395)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1349)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1320)
... 19 more

Nov 09, 2018 5:00:26 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class [org.springframework.web.context.ContextLoaderListener]
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl] for bean with name 'userDetailsService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1328)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:622)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:591)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1397)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:968)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:735)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4745)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5207)
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:748)
Caused by: java.lang.ClassNotFoundException: co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1291)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:249)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:395)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1349)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1320)
... 19 more

Nov 09, 2018 5:00:26 PM com.sun.faces.config.ConfigureListener contextInitialized
INFO: Initializing Mojarra 2.2.10 ( 20150205-0906 https://svn.java.net/svn/mojarra~svn/tags/2.2.10@14334) for context '/JSF_SPRING_HIBERNATE'
Nov 09, 2018 5:00:27 PM com.sun.faces.spi.InjectionProviderFactory createInstance
INFO: JSF1048: PostConstruct/PreDestroy annotations present. ManagedBeans methods marked with these annotations will have said annotations processed.
Nov 09, 2018 5:00:27 PM com.sun.faces.config.ConfigureListener$WebConfigResourceMonitor$Monitor <init>
INFO: Monitoring file:/C:/Users/x4180/workspace1/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/JSF_SPRING_HIBERNATE/WEB-INF/faces-config.xml for modifications
Nov 09, 2018 5:00:27 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: One or more listeners failed to start. Full details will be found in the appropriate container log file
Nov 09, 2018 5:00:27 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/JSF_SPRING_HIBERNATE] startup failed due to previous errors
Nov 09, 2018 5:00:27 PM org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
Nov 09, 2018 5:00:27 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc
WARNING: The web application [JSF_SPRING_HIBERNATE] registered the JDBC driver [com.microsoft.sqlserver.jdbc.SQLServerDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Nov 09, 2018 5:00:27 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
WARNING: The web application [JSF_SPRING_HIBERNATE] appears to have started a thread named [Mojarra-WebResourceMonitor-1-thread-1] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
sun.misc.Unsafe.compareAndSwapInt(Native Method)
java.util.concurrent.atomic.AtomicInteger.compareAndSet(AtomicInteger.java:133)
java.util.concurrent.ThreadPoolExecutor.compareAndDecrementWorkerCount(ThreadPoolExecutor.java:421)
java.util.concurrent.ThreadPoolExecutor.decrementWorkerCount(ThreadPoolExecutor.java:430)
java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1048)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:748)
Nov 09, 2018 5:00:27 PM org.apache.catalina.loader.WebappClassLoaderBase checkThreadLocalMapForLeaks
SEVERE: The web application [JSF_SPRING_HIBERNATE] created a ThreadLocal with key of type [com.microsoft.sqlserver.jdbc.ActivityCorrelator$1] (value [com.microsoft.sqlserver.jdbc.ActivityCorrelator$1@66507bd3]) and a value of type [com.microsoft.sqlserver.jdbc.ActivityId] (value [ce07abca-cce2-4b61-8d6a-65a51418366a-17]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Nov 09, 2018 5:00:27 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Nov 09, 2018 5:00:27 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Nov 09, 2018 5:00:27 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 27085 ms


POM.XML



<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>JSF_SPRING_HIBERNATE</groupId>
<artifactId>JSF_SPRING_HIBERNATE</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>JSF_SPRING_HIBERNATE Maven Webapp</name>
<url>http://maven.apache.org</url>


<properties>
<java.version>1.8</java.version>
<spring.version>4.1.6.RELEASE</spring.version>
<jsf2.version>2.2.10</jsf2.version>
<hibernate.version>4.3.8.Final</hibernate.version>
</properties>

<dependencies>
<!-- Spring and Transactions -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>

<!-- Spring ORM support -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>

<!-- JSF Dependencies -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>${jsf2.version}</version>
</dependency>

<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>${jsf2.version}</version>
</dependency>

<!-- hibernate 4 -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>

<!-- database pool -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.0</version>
</dependency>

<!-- sql server java connector -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.1.0.jre8</version>
</dependency>
</dependencies>
<build>
<finalName>JSF_SPRING_HIBERNATE</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>


WEB.XML



<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>


ApplicationContext.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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd">

<!-- support spring annotation -->
<context:annotation-config />
<!-- support annotation transaction -->
<tx:annotation-driven transaction-manager="transactionManager" />

<!-- declare datasource -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<property name="url" value="jdbc:sqlserver://CIS-GIASDBT2:3433;databaseName=PNXProjectBWrk;integratedSecurity=true" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>

<!--Hibernate session factory configuration -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- load hibernate configuration file -->
<property name="configLocation" value="/WEB-INF/hibernate.cfg.xml" />
<!-- where to find the ORM classes -->
<property name="packagesToScan" value="co.MyJavaCode.hibernate.model" />
</bean>

<!-- Transaction manager -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<!-- service -->
<bean id="userDetailsService" class="co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl" />

<!-- dao -->
<bean id="userDetailsDao" class="co.MyJavaCode.spring.dao.impl.UserDetailsDaoImpl" />

</beans>


faces-config.xml



**<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
<application>
<el-resolver>
org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver>
</application>
</faces-config>**


Click link :Package Structure
I'm stuck in the process and couldn't get what exactly I'm missing. Tried to do it in several way but didn't succeed. googled a lot but couldn't get the solution.



Please help!



UserDetailsServiceImpl.Java



package co.MyJavaCode.spring.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import co.MyJavaCode.hibernate.model.UserDetails;
import co.MyJavaCode.spring.dao.UserDetailsDao;
import co.MyJavaCode.spring.service.UserDetailsService;

@Component
public class UserDetailsServiceImpl implements UserDetailsService {

@Autowired
private UserDetailsDao userDetailsDao;

@Override
public UserDetails getuserDetails(int id) {
return userDetailsDao.getuserDetails(id);
}

@Override
public List<UserDetails> getAllUserDetails() {
return userDetailsDao.getAllUserDetails();
}

public UserDetailsDao getUserDetailsDao() {
return userDetailsDao;
}

}


UserDetailsDaoImpl.java



package co.MyJavaCode.spring.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import co.MyJavaCode.hibernate.model.UserDetails;
import co.MyJavaCode.spring.dao.UserDetailsDao;

@Component
public class UserDetailsDaoImpl implements UserDetailsDao {

@Autowired
private SessionFactory sessionFactory;

@Transactional
@Override
public UserDetails getuserDetails(int id) {
UserDetails userDetails = (UserDetails) sessionFactory.getCurrentSession().get(UserDetails.class, id);
return userDetails;
}

@Transactional
@Override
public List<UserDetails> getAllUserDetails() {

@SuppressWarnings("unchecked")
List<UserDetails> userDetails = (List<UserDetails>) sessionFactory.getCurrentSession()
.createCriteria(UserDetails.class).list();

//or below query

/*
* @SuppressWarnings("unchecked") List<UserDetails> userDetails =
* (List<UserDetails>)sessionFactory.getCurrentSession().createQuery(
* "from UserDetails").list();
*/
return userDetails;
}

public SessionFactory getSessionFactory() {
return sessionFactory;
}

}









share|improve this question

























  • Can you show me your package structure? Normally, this is a problem with the component scan.

    – Alain Cruz
    Nov 9 '18 at 22:16













  • Added the package structure

    – Sumantra Chakraborty
    Nov 12 '18 at 15:26











  • You added the @Component or @Service annotation to your classes, right?

    – Alain Cruz
    Nov 12 '18 at 18:22











  • I've added @Component in my UserDetailsServiceImpl.java and UserDetailsDaoImpl.java. Attached the code snippebts for both these classes.

    – Sumantra Chakraborty
    Nov 12 '18 at 22:32











  • Do you have any suggestion on this?

    – Sumantra Chakraborty
    Nov 14 '18 at 14:38














-1












-1








-1








I'm new to Spring. Trying to build a Web project using JSF Spring and hibernate in Maven but seems my application is not able to get the spring configuration XML.



Below is the Stack Trace:



WARNING: Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl] for bean with name 'userDetailsService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1328)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:622)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:591)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1397)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:968)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:735)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4745)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5207)
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:748)
Caused by: java.lang.ClassNotFoundException: co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1291)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:249)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:395)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1349)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1320)
... 19 more

Nov 09, 2018 5:00:26 PM org.springframework.web.context.ContextLoader initWebApplicationContext
SEVERE: Context initialization failed
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl] for bean with name 'userDetailsService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1328)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:622)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:591)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1397)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:968)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:735)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4745)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5207)
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:748)
Caused by: java.lang.ClassNotFoundException: co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1291)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:249)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:395)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1349)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1320)
... 19 more

Nov 09, 2018 5:00:26 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class [org.springframework.web.context.ContextLoaderListener]
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl] for bean with name 'userDetailsService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1328)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:622)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:591)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1397)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:968)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:735)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4745)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5207)
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:748)
Caused by: java.lang.ClassNotFoundException: co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1291)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:249)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:395)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1349)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1320)
... 19 more

Nov 09, 2018 5:00:26 PM com.sun.faces.config.ConfigureListener contextInitialized
INFO: Initializing Mojarra 2.2.10 ( 20150205-0906 https://svn.java.net/svn/mojarra~svn/tags/2.2.10@14334) for context '/JSF_SPRING_HIBERNATE'
Nov 09, 2018 5:00:27 PM com.sun.faces.spi.InjectionProviderFactory createInstance
INFO: JSF1048: PostConstruct/PreDestroy annotations present. ManagedBeans methods marked with these annotations will have said annotations processed.
Nov 09, 2018 5:00:27 PM com.sun.faces.config.ConfigureListener$WebConfigResourceMonitor$Monitor <init>
INFO: Monitoring file:/C:/Users/x4180/workspace1/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/JSF_SPRING_HIBERNATE/WEB-INF/faces-config.xml for modifications
Nov 09, 2018 5:00:27 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: One or more listeners failed to start. Full details will be found in the appropriate container log file
Nov 09, 2018 5:00:27 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/JSF_SPRING_HIBERNATE] startup failed due to previous errors
Nov 09, 2018 5:00:27 PM org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
Nov 09, 2018 5:00:27 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc
WARNING: The web application [JSF_SPRING_HIBERNATE] registered the JDBC driver [com.microsoft.sqlserver.jdbc.SQLServerDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Nov 09, 2018 5:00:27 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
WARNING: The web application [JSF_SPRING_HIBERNATE] appears to have started a thread named [Mojarra-WebResourceMonitor-1-thread-1] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
sun.misc.Unsafe.compareAndSwapInt(Native Method)
java.util.concurrent.atomic.AtomicInteger.compareAndSet(AtomicInteger.java:133)
java.util.concurrent.ThreadPoolExecutor.compareAndDecrementWorkerCount(ThreadPoolExecutor.java:421)
java.util.concurrent.ThreadPoolExecutor.decrementWorkerCount(ThreadPoolExecutor.java:430)
java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1048)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:748)
Nov 09, 2018 5:00:27 PM org.apache.catalina.loader.WebappClassLoaderBase checkThreadLocalMapForLeaks
SEVERE: The web application [JSF_SPRING_HIBERNATE] created a ThreadLocal with key of type [com.microsoft.sqlserver.jdbc.ActivityCorrelator$1] (value [com.microsoft.sqlserver.jdbc.ActivityCorrelator$1@66507bd3]) and a value of type [com.microsoft.sqlserver.jdbc.ActivityId] (value [ce07abca-cce2-4b61-8d6a-65a51418366a-17]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Nov 09, 2018 5:00:27 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Nov 09, 2018 5:00:27 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Nov 09, 2018 5:00:27 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 27085 ms


POM.XML



<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>JSF_SPRING_HIBERNATE</groupId>
<artifactId>JSF_SPRING_HIBERNATE</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>JSF_SPRING_HIBERNATE Maven Webapp</name>
<url>http://maven.apache.org</url>


<properties>
<java.version>1.8</java.version>
<spring.version>4.1.6.RELEASE</spring.version>
<jsf2.version>2.2.10</jsf2.version>
<hibernate.version>4.3.8.Final</hibernate.version>
</properties>

<dependencies>
<!-- Spring and Transactions -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>

<!-- Spring ORM support -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>

<!-- JSF Dependencies -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>${jsf2.version}</version>
</dependency>

<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>${jsf2.version}</version>
</dependency>

<!-- hibernate 4 -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>

<!-- database pool -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.0</version>
</dependency>

<!-- sql server java connector -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.1.0.jre8</version>
</dependency>
</dependencies>
<build>
<finalName>JSF_SPRING_HIBERNATE</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>


WEB.XML



<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>


ApplicationContext.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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd">

<!-- support spring annotation -->
<context:annotation-config />
<!-- support annotation transaction -->
<tx:annotation-driven transaction-manager="transactionManager" />

<!-- declare datasource -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<property name="url" value="jdbc:sqlserver://CIS-GIASDBT2:3433;databaseName=PNXProjectBWrk;integratedSecurity=true" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>

<!--Hibernate session factory configuration -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- load hibernate configuration file -->
<property name="configLocation" value="/WEB-INF/hibernate.cfg.xml" />
<!-- where to find the ORM classes -->
<property name="packagesToScan" value="co.MyJavaCode.hibernate.model" />
</bean>

<!-- Transaction manager -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<!-- service -->
<bean id="userDetailsService" class="co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl" />

<!-- dao -->
<bean id="userDetailsDao" class="co.MyJavaCode.spring.dao.impl.UserDetailsDaoImpl" />

</beans>


faces-config.xml



**<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
<application>
<el-resolver>
org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver>
</application>
</faces-config>**


Click link :Package Structure
I'm stuck in the process and couldn't get what exactly I'm missing. Tried to do it in several way but didn't succeed. googled a lot but couldn't get the solution.



Please help!



UserDetailsServiceImpl.Java



package co.MyJavaCode.spring.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import co.MyJavaCode.hibernate.model.UserDetails;
import co.MyJavaCode.spring.dao.UserDetailsDao;
import co.MyJavaCode.spring.service.UserDetailsService;

@Component
public class UserDetailsServiceImpl implements UserDetailsService {

@Autowired
private UserDetailsDao userDetailsDao;

@Override
public UserDetails getuserDetails(int id) {
return userDetailsDao.getuserDetails(id);
}

@Override
public List<UserDetails> getAllUserDetails() {
return userDetailsDao.getAllUserDetails();
}

public UserDetailsDao getUserDetailsDao() {
return userDetailsDao;
}

}


UserDetailsDaoImpl.java



package co.MyJavaCode.spring.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import co.MyJavaCode.hibernate.model.UserDetails;
import co.MyJavaCode.spring.dao.UserDetailsDao;

@Component
public class UserDetailsDaoImpl implements UserDetailsDao {

@Autowired
private SessionFactory sessionFactory;

@Transactional
@Override
public UserDetails getuserDetails(int id) {
UserDetails userDetails = (UserDetails) sessionFactory.getCurrentSession().get(UserDetails.class, id);
return userDetails;
}

@Transactional
@Override
public List<UserDetails> getAllUserDetails() {

@SuppressWarnings("unchecked")
List<UserDetails> userDetails = (List<UserDetails>) sessionFactory.getCurrentSession()
.createCriteria(UserDetails.class).list();

//or below query

/*
* @SuppressWarnings("unchecked") List<UserDetails> userDetails =
* (List<UserDetails>)sessionFactory.getCurrentSession().createQuery(
* "from UserDetails").list();
*/
return userDetails;
}

public SessionFactory getSessionFactory() {
return sessionFactory;
}

}









share|improve this question
















I'm new to Spring. Trying to build a Web project using JSF Spring and hibernate in Maven but seems my application is not able to get the spring configuration XML.



Below is the Stack Trace:



WARNING: Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl] for bean with name 'userDetailsService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1328)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:622)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:591)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1397)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:968)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:735)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4745)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5207)
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:748)
Caused by: java.lang.ClassNotFoundException: co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1291)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:249)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:395)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1349)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1320)
... 19 more

Nov 09, 2018 5:00:26 PM org.springframework.web.context.ContextLoader initWebApplicationContext
SEVERE: Context initialization failed
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl] for bean with name 'userDetailsService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1328)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:622)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:591)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1397)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:968)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:735)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4745)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5207)
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:748)
Caused by: java.lang.ClassNotFoundException: co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1291)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:249)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:395)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1349)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1320)
... 19 more

Nov 09, 2018 5:00:26 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class [org.springframework.web.context.ContextLoaderListener]
org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl] for bean with name 'userDetailsService' defined in ServletContext resource [/WEB-INF/applicationContext.xml]; nested exception is java.lang.ClassNotFoundException: co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1328)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:622)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:591)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1397)
at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:968)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:735)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4745)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5207)
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:748)
Caused by: java.lang.ClassNotFoundException: co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1291)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:249)
at org.springframework.beans.factory.support.AbstractBeanDefinition.resolveBeanClass(AbstractBeanDefinition.java:395)
at org.springframework.beans.factory.support.AbstractBeanFactory.doResolveBeanClass(AbstractBeanFactory.java:1349)
at org.springframework.beans.factory.support.AbstractBeanFactory.resolveBeanClass(AbstractBeanFactory.java:1320)
... 19 more

Nov 09, 2018 5:00:26 PM com.sun.faces.config.ConfigureListener contextInitialized
INFO: Initializing Mojarra 2.2.10 ( 20150205-0906 https://svn.java.net/svn/mojarra~svn/tags/2.2.10@14334) for context '/JSF_SPRING_HIBERNATE'
Nov 09, 2018 5:00:27 PM com.sun.faces.spi.InjectionProviderFactory createInstance
INFO: JSF1048: PostConstruct/PreDestroy annotations present. ManagedBeans methods marked with these annotations will have said annotations processed.
Nov 09, 2018 5:00:27 PM com.sun.faces.config.ConfigureListener$WebConfigResourceMonitor$Monitor <init>
INFO: Monitoring file:/C:/Users/x4180/workspace1/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/JSF_SPRING_HIBERNATE/WEB-INF/faces-config.xml for modifications
Nov 09, 2018 5:00:27 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: One or more listeners failed to start. Full details will be found in the appropriate container log file
Nov 09, 2018 5:00:27 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/JSF_SPRING_HIBERNATE] startup failed due to previous errors
Nov 09, 2018 5:00:27 PM org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
Nov 09, 2018 5:00:27 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesJdbc
WARNING: The web application [JSF_SPRING_HIBERNATE] registered the JDBC driver [com.microsoft.sqlserver.jdbc.SQLServerDriver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
Nov 09, 2018 5:00:27 PM org.apache.catalina.loader.WebappClassLoaderBase clearReferencesThreads
WARNING: The web application [JSF_SPRING_HIBERNATE] appears to have started a thread named [Mojarra-WebResourceMonitor-1-thread-1] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
sun.misc.Unsafe.compareAndSwapInt(Native Method)
java.util.concurrent.atomic.AtomicInteger.compareAndSet(AtomicInteger.java:133)
java.util.concurrent.ThreadPoolExecutor.compareAndDecrementWorkerCount(ThreadPoolExecutor.java:421)
java.util.concurrent.ThreadPoolExecutor.decrementWorkerCount(ThreadPoolExecutor.java:430)
java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1048)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
java.lang.Thread.run(Thread.java:748)
Nov 09, 2018 5:00:27 PM org.apache.catalina.loader.WebappClassLoaderBase checkThreadLocalMapForLeaks
SEVERE: The web application [JSF_SPRING_HIBERNATE] created a ThreadLocal with key of type [com.microsoft.sqlserver.jdbc.ActivityCorrelator$1] (value [com.microsoft.sqlserver.jdbc.ActivityCorrelator$1@66507bd3]) and a value of type [com.microsoft.sqlserver.jdbc.ActivityId] (value [ce07abca-cce2-4b61-8d6a-65a51418366a-17]) but failed to remove it when the web application was stopped. Threads are going to be renewed over time to try and avoid a probable memory leak.
Nov 09, 2018 5:00:27 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Nov 09, 2018 5:00:27 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Nov 09, 2018 5:00:27 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 27085 ms


POM.XML



<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>JSF_SPRING_HIBERNATE</groupId>
<artifactId>JSF_SPRING_HIBERNATE</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>JSF_SPRING_HIBERNATE Maven Webapp</name>
<url>http://maven.apache.org</url>


<properties>
<java.version>1.8</java.version>
<spring.version>4.1.6.RELEASE</spring.version>
<jsf2.version>2.2.10</jsf2.version>
<hibernate.version>4.3.8.Final</hibernate.version>
</properties>

<dependencies>
<!-- Spring and Transactions -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>

<!-- Spring ORM support -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${spring.version}</version>
</dependency>

<!-- JSF Dependencies -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>${jsf2.version}</version>
</dependency>

<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>${jsf2.version}</version>
</dependency>

<!-- hibernate 4 -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>

<!-- database pool -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
<version>2.0</version>
</dependency>

<!-- sql server java connector -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.1.0.jre8</version>
</dependency>
</dependencies>
<build>
<finalName>JSF_SPRING_HIBERNATE</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</build>
</project>


WEB.XML



<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>


ApplicationContext.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:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd">

<!-- support spring annotation -->
<context:annotation-config />
<!-- support annotation transaction -->
<tx:annotation-driven transaction-manager="transactionManager" />

<!-- declare datasource -->
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
<property name="url" value="jdbc:sqlserver://CIS-GIASDBT2:3433;databaseName=PNXProjectBWrk;integratedSecurity=true" />
<property name="username" value="root" />
<property name="password" value="" />
</bean>

<!--Hibernate session factory configuration -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<!-- load hibernate configuration file -->
<property name="configLocation" value="/WEB-INF/hibernate.cfg.xml" />
<!-- where to find the ORM classes -->
<property name="packagesToScan" value="co.MyJavaCode.hibernate.model" />
</bean>

<!-- Transaction manager -->
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>

<!-- service -->
<bean id="userDetailsService" class="co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl" />

<!-- dao -->
<bean id="userDetailsDao" class="co.MyJavaCode.spring.dao.impl.UserDetailsDaoImpl" />

</beans>


faces-config.xml



**<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">
<application>
<el-resolver>
org.springframework.web.jsf.el.SpringBeanFacesELResolver
</el-resolver>
</application>
</faces-config>**


Click link :Package Structure
I'm stuck in the process and couldn't get what exactly I'm missing. Tried to do it in several way but didn't succeed. googled a lot but couldn't get the solution.



Please help!



UserDetailsServiceImpl.Java



package co.MyJavaCode.spring.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import co.MyJavaCode.hibernate.model.UserDetails;
import co.MyJavaCode.spring.dao.UserDetailsDao;
import co.MyJavaCode.spring.service.UserDetailsService;

@Component
public class UserDetailsServiceImpl implements UserDetailsService {

@Autowired
private UserDetailsDao userDetailsDao;

@Override
public UserDetails getuserDetails(int id) {
return userDetailsDao.getuserDetails(id);
}

@Override
public List<UserDetails> getAllUserDetails() {
return userDetailsDao.getAllUserDetails();
}

public UserDetailsDao getUserDetailsDao() {
return userDetailsDao;
}

}


UserDetailsDaoImpl.java



package co.MyJavaCode.spring.dao.impl;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import co.MyJavaCode.hibernate.model.UserDetails;
import co.MyJavaCode.spring.dao.UserDetailsDao;

@Component
public class UserDetailsDaoImpl implements UserDetailsDao {

@Autowired
private SessionFactory sessionFactory;

@Transactional
@Override
public UserDetails getuserDetails(int id) {
UserDetails userDetails = (UserDetails) sessionFactory.getCurrentSession().get(UserDetails.class, id);
return userDetails;
}

@Transactional
@Override
public List<UserDetails> getAllUserDetails() {

@SuppressWarnings("unchecked")
List<UserDetails> userDetails = (List<UserDetails>) sessionFactory.getCurrentSession()
.createCriteria(UserDetails.class).list();

//or below query

/*
* @SuppressWarnings("unchecked") List<UserDetails> userDetails =
* (List<UserDetails>)sessionFactory.getCurrentSession().createQuery(
* "from UserDetails").list();
*/
return userDetails;
}

public SessionFactory getSessionFactory() {
return sessionFactory;
}

}






spring hibernate jsf






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 12 '18 at 22:31







Sumantra Chakraborty

















asked Nov 9 '18 at 22:13









Sumantra ChakrabortySumantra Chakraborty

65




65













  • Can you show me your package structure? Normally, this is a problem with the component scan.

    – Alain Cruz
    Nov 9 '18 at 22:16













  • Added the package structure

    – Sumantra Chakraborty
    Nov 12 '18 at 15:26











  • You added the @Component or @Service annotation to your classes, right?

    – Alain Cruz
    Nov 12 '18 at 18:22











  • I've added @Component in my UserDetailsServiceImpl.java and UserDetailsDaoImpl.java. Attached the code snippebts for both these classes.

    – Sumantra Chakraborty
    Nov 12 '18 at 22:32











  • Do you have any suggestion on this?

    – Sumantra Chakraborty
    Nov 14 '18 at 14:38



















  • Can you show me your package structure? Normally, this is a problem with the component scan.

    – Alain Cruz
    Nov 9 '18 at 22:16













  • Added the package structure

    – Sumantra Chakraborty
    Nov 12 '18 at 15:26











  • You added the @Component or @Service annotation to your classes, right?

    – Alain Cruz
    Nov 12 '18 at 18:22











  • I've added @Component in my UserDetailsServiceImpl.java and UserDetailsDaoImpl.java. Attached the code snippebts for both these classes.

    – Sumantra Chakraborty
    Nov 12 '18 at 22:32











  • Do you have any suggestion on this?

    – Sumantra Chakraborty
    Nov 14 '18 at 14:38

















Can you show me your package structure? Normally, this is a problem with the component scan.

– Alain Cruz
Nov 9 '18 at 22:16







Can you show me your package structure? Normally, this is a problem with the component scan.

– Alain Cruz
Nov 9 '18 at 22:16















Added the package structure

– Sumantra Chakraborty
Nov 12 '18 at 15:26





Added the package structure

– Sumantra Chakraborty
Nov 12 '18 at 15:26













You added the @Component or @Service annotation to your classes, right?

– Alain Cruz
Nov 12 '18 at 18:22





You added the @Component or @Service annotation to your classes, right?

– Alain Cruz
Nov 12 '18 at 18:22













I've added @Component in my UserDetailsServiceImpl.java and UserDetailsDaoImpl.java. Attached the code snippebts for both these classes.

– Sumantra Chakraborty
Nov 12 '18 at 22:32





I've added @Component in my UserDetailsServiceImpl.java and UserDetailsDaoImpl.java. Attached the code snippebts for both these classes.

– Sumantra Chakraborty
Nov 12 '18 at 22:32













Do you have any suggestion on this?

– Sumantra Chakraborty
Nov 14 '18 at 14:38





Do you have any suggestion on this?

– Sumantra Chakraborty
Nov 14 '18 at 14:38












1 Answer
1






active

oldest

votes


















0














I believe your problem has to do with the component scan. In this blog, it seems that in order to use your configuration, you must add the following annotation, @ManagedBean to your beans.



Still, there is an easier way to do a complete scan, which is allowing Spring to do it for you. For this you might try deleting the following lines from your applicationContext.xml.



<!-- service -->
<bean id="userDetailsService" class="co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl" />

<!-- dao -->
<bean id="userDetailsDao" class="co.MyJavaCode.spring.dao.impl.UserDetailsDaoImpl" />


After deleting those lines, add the following line to the same file.



<context:component-scan base-package="co.MyJavaCode"/>


This will automatically scan all your files that have either the @Component or @Service annotation. I Added co.MyJavaCode as the base package, because it looks like every class is inside that package, but if not, just create a base package and add everything to it and use it as reference for your auto-scan. Hope it helps!






share|improve this answer


























  • New versions of spring also understand the cdi @Named annotation.

    – Kukeltje
    Nov 14 '18 at 18:35











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233937%2fintegrating-jsf-spring-and-hibernate-and-always-getting-the-error-org-springfra%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I believe your problem has to do with the component scan. In this blog, it seems that in order to use your configuration, you must add the following annotation, @ManagedBean to your beans.



Still, there is an easier way to do a complete scan, which is allowing Spring to do it for you. For this you might try deleting the following lines from your applicationContext.xml.



<!-- service -->
<bean id="userDetailsService" class="co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl" />

<!-- dao -->
<bean id="userDetailsDao" class="co.MyJavaCode.spring.dao.impl.UserDetailsDaoImpl" />


After deleting those lines, add the following line to the same file.



<context:component-scan base-package="co.MyJavaCode"/>


This will automatically scan all your files that have either the @Component or @Service annotation. I Added co.MyJavaCode as the base package, because it looks like every class is inside that package, but if not, just create a base package and add everything to it and use it as reference for your auto-scan. Hope it helps!






share|improve this answer


























  • New versions of spring also understand the cdi @Named annotation.

    – Kukeltje
    Nov 14 '18 at 18:35
















0














I believe your problem has to do with the component scan. In this blog, it seems that in order to use your configuration, you must add the following annotation, @ManagedBean to your beans.



Still, there is an easier way to do a complete scan, which is allowing Spring to do it for you. For this you might try deleting the following lines from your applicationContext.xml.



<!-- service -->
<bean id="userDetailsService" class="co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl" />

<!-- dao -->
<bean id="userDetailsDao" class="co.MyJavaCode.spring.dao.impl.UserDetailsDaoImpl" />


After deleting those lines, add the following line to the same file.



<context:component-scan base-package="co.MyJavaCode"/>


This will automatically scan all your files that have either the @Component or @Service annotation. I Added co.MyJavaCode as the base package, because it looks like every class is inside that package, but if not, just create a base package and add everything to it and use it as reference for your auto-scan. Hope it helps!






share|improve this answer


























  • New versions of spring also understand the cdi @Named annotation.

    – Kukeltje
    Nov 14 '18 at 18:35














0












0








0







I believe your problem has to do with the component scan. In this blog, it seems that in order to use your configuration, you must add the following annotation, @ManagedBean to your beans.



Still, there is an easier way to do a complete scan, which is allowing Spring to do it for you. For this you might try deleting the following lines from your applicationContext.xml.



<!-- service -->
<bean id="userDetailsService" class="co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl" />

<!-- dao -->
<bean id="userDetailsDao" class="co.MyJavaCode.spring.dao.impl.UserDetailsDaoImpl" />


After deleting those lines, add the following line to the same file.



<context:component-scan base-package="co.MyJavaCode"/>


This will automatically scan all your files that have either the @Component or @Service annotation. I Added co.MyJavaCode as the base package, because it looks like every class is inside that package, but if not, just create a base package and add everything to it and use it as reference for your auto-scan. Hope it helps!






share|improve this answer















I believe your problem has to do with the component scan. In this blog, it seems that in order to use your configuration, you must add the following annotation, @ManagedBean to your beans.



Still, there is an easier way to do a complete scan, which is allowing Spring to do it for you. For this you might try deleting the following lines from your applicationContext.xml.



<!-- service -->
<bean id="userDetailsService" class="co.MyJavaCode.spring.service.impl.UserDetailsServiceImpl" />

<!-- dao -->
<bean id="userDetailsDao" class="co.MyJavaCode.spring.dao.impl.UserDetailsDaoImpl" />


After deleting those lines, add the following line to the same file.



<context:component-scan base-package="co.MyJavaCode"/>


This will automatically scan all your files that have either the @Component or @Service annotation. I Added co.MyJavaCode as the base package, because it looks like every class is inside that package, but if not, just create a base package and add everything to it and use it as reference for your auto-scan. Hope it helps!







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 14 '18 at 15:02

























answered Nov 14 '18 at 14:55









Alain CruzAlain Cruz

2,1083918




2,1083918













  • New versions of spring also understand the cdi @Named annotation.

    – Kukeltje
    Nov 14 '18 at 18:35



















  • New versions of spring also understand the cdi @Named annotation.

    – Kukeltje
    Nov 14 '18 at 18:35

















New versions of spring also understand the cdi @Named annotation.

– Kukeltje
Nov 14 '18 at 18:35





New versions of spring also understand the cdi @Named annotation.

– Kukeltje
Nov 14 '18 at 18:35




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53233937%2fintegrating-jsf-spring-and-hibernate-and-always-getting-the-error-org-springfra%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Florida Star v. B. J. F.

Danny Elfman

Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues