Hello World with Spring Framework and JSF integration!

Take a look at this please where Spring and JSF is integrated.

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>biz.tugay</groupId>
 
    <artifactId>jsf-one</artifactId>
    <packaging>war</packaging>
 
    <version>1.0-SNAPSHOT</version>
    <name>jsf-one Maven Webapp</name>
 
    <url>http://maven.apache.org</url>
 
    <dependencies>
 
        <dependency>
            <groupId>javax.faces</groupId>
            <artifactId>javax.faces-api</artifactId>
            <version>2.2</version>
        </dependency>
 
        <dependency>
            <groupId>com.sun.faces</groupId>
            <artifactId>jsf-impl</artifactId>
            <version>2.2.13</version>
        </dependency>
 
        <!-- Spring Framework -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.2.5.RELEASE</version>
        </dependency>
 
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>4.2.5.RELEASE</version>
        </dependency>
        <!-- Spring Framework -->
 
    </dependencies>
 
    <properties>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
    </properties>
 
    <build>
        <finalName>jsf-one</finalName>
        <plugins>
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.2.1.v20140609</version>
                <configuration>
                    <scanIntervalSeconds>2</scanIntervalSeconds>
                    <webApp>
                        <contextPath>/</contextPath>
                    </webApp>
                </configuration>
            </plugin>
        </plugins>
    </build>
 
</project>

web.xml
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                             http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0">
 
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
 
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
 
    <listener>
        <listener-class>
            org.springframework.web.context.request.RequestContextListener
        </listener-class>
    </listener>
 
 
    <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>*.xhtml</url-pattern>
    </servlet-mapping>
 
    <welcome-file-list>
        <welcome-file>index.xhtml</welcome-file>
    </welcome-file-list>
 
</web-app>

faces-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                                  http://java.sun.com/xml/ns/javaee/web-facesconfig_2_1.xsd"
              version="2.1">
 
    <application>
        <el-resolver>
            org.springframework.web.jsf.el.SpringBeanFacesELResolver
        </el-resolver>
    </application>
</faces-config>

applicationContext.xml
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           https://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
 
    <bean id="myManagedBean" class="biz.tugay.jsfone.MyManagedBeanImpl" scope="request" >
        <property name="serviceBean" ref="serviceBean"/>
    </bean>
 
    <bean id="serviceBean" class="biz.tugay.jsfone.ServiceBeanImpl" />
</beans>

ServiceBean.java
package biz.tugay.jsfone;
 
/**
 * User: koray@tugay.biz on 10/05/16 at 14:40.
 */
public interface ServiceBean {
 
    String sayHello();
}

ServiceBeanImpl.java
package biz.tugay.jsfone;
 
/**
 * User: koray@tugay.biz on 10/05/16 at 14:42.
 */
public class ServiceBeanImpl implements ServiceBean {
 
    public String sayHello() {
        return "Hello World";
    }
}

MyManagedBean.java
package biz.tugay.jsfone;
 
import org.springframework.beans.factory.annotation.Required;
 
/**
 * User: koray@tugay.biz on 10/05/16 at 11:51.
 */
 
public class MyManagedBeanImpl {
 
    private ServiceBean serviceBean;
 
    public String sayHello(){
        return serviceBean.sayHello();
    }
 
    @Required
    public void setServiceBean(ServiceBean serviceBean) {
        this.serviceBean = serviceBean;
    }
}

index.xhtml
<!DOCTYPE html>
<html xmlns:h="http://xmlns.jcp.org/jsf/html">
<head>
    <title>Hello World!!!</title>
</head>
<h:body>
    <h:outputLabel value="#{myManagedBean.sayHello()}"/>
</h:body>
</html>

Here is the Project Directory Layout

And this is how I build the application and trigger jetty:
Korays-MacBook-Pro:jsf-one koraytugay$ mvn clean install
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building jsf-one Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ jsf-one ---
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ jsf-one ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ jsf-one ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 3 source files to /Users/koraytugay/Development/jsf - learning/jsf-one/target/classes
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ jsf-one ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/koraytugay/Development/jsf - learning/jsf-one/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ jsf-one ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ jsf-one ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-war-plugin:2.2:war (default-war) @ jsf-one ---
[INFO] Packaging webapp
[INFO] Assembling webapp [jsf-one] in [/Users/koraytugay/Development/jsf - learning/jsf-one/target/jsf-one]
[INFO] Processing war project
[INFO] Copying webapp resources [/Users/koraytugay/Development/jsf - learning/jsf-one/src/main/webapp]
[INFO] Webapp assembled in [49 msecs]
[INFO] Building war: /Users/koraytugay/Development/jsf - learning/jsf-one/target/jsf-one.war
[INFO] WEB-INF/web.xml already added, skipping
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ jsf-one ---
[INFO] Installing /Users/koraytugay/Development/jsf - learning/jsf-one/target/jsf-one.war to /Users/koraytugay/.m2/repository/biz/tugay/jsf-one/1.0-SNAPSHOT/jsf-one-1.0-SNAPSHOT.war
[INFO] Installing /Users/koraytugay/Development/jsf - learning/jsf-one/pom.xml to /Users/koraytugay/.m2/repository/biz/tugay/jsf-one/1.0-SNAPSHOT/jsf-one-1.0-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.909 s
[INFO] Finished at: 2016-05-10T15:22:03+03:00
[INFO] Final Memory: 18M/216M
[INFO] ------------------------------------------------------------------------
Korays-MacBook-Pro:jsf-one koraytugay$ mvn jetty:start
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building jsf-one Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] >>> jetty-maven-plugin:9.2.1.v20140609:start (default-cli) > validate @ jsf-one >>>
[INFO] 
[INFO] <<< jetty-maven-plugin:9.2.1.v20140609:start (default-cli) < validate @ jsf-one <<<
[INFO] 
[INFO] --- jetty-maven-plugin:9.2.1.v20140609:start (default-cli) @ jsf-one ---
[INFO] Logging initialized @1306ms
[INFO] Configuring Jetty for project: jsf-one Maven Webapp
[INFO] webAppSourceDirectory not set. Trying src/main/webapp
[INFO] Reload Mechanic: automatic
[INFO] Classes = /Users/koraytugay/Development/jsf - learning/jsf-one/target/classes
[INFO] Context path = /
[INFO] Tmp directory = /Users/koraytugay/Development/jsf - learning/jsf-one/target/tmp
[INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml
[INFO] Web overrides =  none
[INFO] web.xml file = file:/Users/koraytugay/Development/jsf%20-%20learning/jsf-one/src/main/webapp/WEB-INF/web.xml
[INFO] Webapp directory = /Users/koraytugay/Development/jsf - learning/jsf-one/src/main/webapp
[INFO] jetty-9.2.1.v20140609
[INFO] No Spring WebApplicationInitializer types detected on classpath
[INFO] Initializing Spring root WebApplicationContext
May 10, 2016 3:22:12 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
May 10, 2016 3:22:12 PM org.springframework.web.context.support.XmlWebApplicationContext prepareRefresh
INFO: Refreshing Root WebApplicationContext: startup date [Tue May 10 15:22:12 EEST 2016]; root of context hierarchy
May 10, 2016 3:22:12 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
May 10, 2016 3:22:14 PM org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 2173 ms
May 10, 2016 3:22:14 PM com.sun.faces.config.ConfigureListener contextInitialized
INFO: Initializing Mojarra 2.2.13 ( 20160203-1910 unable to get svn info) for context ''
May 10, 2016 3:22:14 PM com.sun.faces.spi.InjectionProviderFactory createInstance
INFO: JSF1048: PostConstruct/PreDestroy annotations present.  ManagedBeans methods marked with these annotations will have said annotations processed.
[INFO] Started o.e.j.m.p.JettyWebAppContext@2c282004{/,[file:/Users/koraytugay/Development/jsf%20-%20learning/jsf-one/src/main/webapp/, jar:file:/Users/koraytugay/.m2/repository/com/sun/faces/jsf-impl/2.2.13/jsf-impl-2.2.13.jar!/META-INF/resources],AVAILABLE}{file:/Users/koraytugay/Development/jsf%20-%20learning/jsf-one/src/main/webapp/}
[WARNING] !RequestLog
[INFO] Started ServerConnector@4eba373c{HTTP/1.1}{0.0.0.0:8080}
[INFO] Started @4674ms
[INFO] Started Jetty Server
[INFO] Starting scanner at interval of 2 seconds