-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d62deb3
Showing
11 changed files
with
292 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
*.class | ||
|
||
# Package Files # | ||
*.jar | ||
*.war | ||
*.ear | ||
|
||
/mydb | ||
/target | ||
/.settings | ||
*.classpath | ||
.project | ||
/target/ | ||
/target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.levelup</groupId> | ||
<artifactId>037-integrate-jsf-spring-boot</artifactId> | ||
<version>0.0.1-SNAPSHOT</version> | ||
<packaging>war</packaging> | ||
|
||
<name>037-integrate-jsf-spring-boot</name> | ||
<description>Demo project for Spring Boot</description> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>1.2.5.RELEASE</version> | ||
<relativePath /> <!-- lookup parent from repository --> | ||
</parent> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
<exclusions> | ||
<exclusion> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-tomcat</artifactId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-jetty</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.sun.faces</groupId> | ||
<artifactId>jsf-api</artifactId> | ||
<version>2.2.8</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.sun.faces</groupId> | ||
<artifactId>jsf-impl</artifactId> | ||
<version>2.2.8</version> | ||
<scope>compile</scope> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.levelup; | ||
|
||
import javax.servlet.ServletContext; | ||
import javax.servlet.ServletException; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.context.embedded.ServletContextInitializer; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
|
||
@SpringBootApplication | ||
public class Application { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(Application.class, args); | ||
} | ||
|
||
@Bean | ||
public JSFSpringBean jsfSpringBean() { | ||
return new JSFSpringBean(); | ||
} | ||
|
||
@Configuration | ||
@Profile("dev") | ||
static class ConfigureJSFContextParameters implements ServletContextInitializer { | ||
|
||
@Override | ||
public void onStartup(ServletContext servletContext) | ||
throws ServletException { | ||
|
||
servletContext.setInitParameter("javax.faces.DEFAULT_SUFFIX", | ||
".xhtml"); | ||
servletContext.setInitParameter( | ||
"javax.faces.PARTIAL_STATE_SAVING_METHOD", "true"); | ||
servletContext.setInitParameter("javax.faces.PROJECT_STAGE", | ||
"Development"); | ||
servletContext.setInitParameter("facelets.DEVELOPMENT", "true"); | ||
servletContext.setInitParameter( | ||
"javax.faces.FACELETS_REFRESH_PERIOD", "1"); | ||
|
||
} | ||
} | ||
|
||
@Configuration | ||
@Profile("production") | ||
static class ConfigureJSFContextParametersProd implements ServletContextInitializer { | ||
|
||
@Override | ||
public void onStartup(ServletContext servletContext) | ||
throws ServletException { | ||
|
||
servletContext.setInitParameter("javax.faces.DEFAULT_SUFFIX", | ||
".xhtml"); | ||
servletContext.setInitParameter( | ||
"javax.faces.PARTIAL_STATE_SAVING_METHOD", "true"); | ||
servletContext.setInitParameter("javax.faces.PROJECT_STAGE", | ||
"Production"); | ||
servletContext.setInitParameter("facelets.DEVELOPMENT", "false"); | ||
servletContext.setInitParameter( | ||
"javax.faces.FACELETS_REFRESH_PERIOD", "-1"); | ||
|
||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.levelup; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import javax.servlet.ServletContext; | ||
import javax.servlet.ServletException; | ||
|
||
import org.springframework.boot.context.embedded.ServletRegistrationBean; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import com.sun.faces.config.FacesInitializer; | ||
|
||
@Configuration | ||
public class ConfigureJSF { | ||
|
||
@Bean | ||
public ServletRegistrationBean facesServletRegistration() { | ||
|
||
ServletRegistrationBean servletRegistrationBean = new JsfServletRegistrationBean(); | ||
|
||
return servletRegistrationBean; | ||
} | ||
|
||
public class JsfServletRegistrationBean extends ServletRegistrationBean { | ||
|
||
public JsfServletRegistrationBean() { | ||
super(); | ||
} | ||
|
||
@Override | ||
public void onStartup(ServletContext servletContext) | ||
throws ServletException { | ||
|
||
FacesInitializer facesInitializer = new FacesInitializer(); | ||
|
||
Set<Class<?>> clazz = new HashSet<Class<?>>(); | ||
clazz.add(ConfigureJSF.class); | ||
facesInitializer.onStartup(clazz, servletContext); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.levelup; | ||
|
||
public class JSFSpringBean { | ||
|
||
private String welcomeMessage = "Populated by spring created bean"; | ||
|
||
public String getWelcomeMessage() { | ||
return welcomeMessage; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.levelup; | ||
|
||
import javax.annotation.ManagedBean; | ||
import javax.faces.bean.RequestScoped; | ||
|
||
@ManagedBean | ||
@RequestScoped | ||
public class JsfBean { | ||
|
||
private String welcomeMessage = "Populated by JSF created bean"; | ||
|
||
public String getWelcomeMessage() { | ||
return welcomeMessage; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.levelup; | ||
|
||
import org.springframework.boot.builder.SpringApplicationBuilder; | ||
import org.springframework.boot.context.web.SpringBootServletInitializer; | ||
|
||
public class ServletInitializer extends SpringBootServletInitializer { | ||
|
||
@Override | ||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { | ||
return application.sources(Application.class); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<faces-config 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/web-facesconfig_2_2.xsd" | ||
version="2.2"> | ||
|
||
<application> | ||
<el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver> | ||
</application> | ||
|
||
<lifecycle> | ||
<phase-listener>org.springframework.web.jsf.DelegatingPhaseListenerMulticaster</phase-listener> | ||
</lifecycle> | ||
|
||
</faces-config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
spring.profiles.active=dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<!DOCTYPE html> | ||
<f:view xmlns="http://www.w3.org/1999/xhtml" | ||
xmlns:ui="http://java.sun.com/jsf/facelets" | ||
xmlns:h="http://xmlns.jcp.org/jsf/html" | ||
xmlns:f="http://xmlns.jcp.org/jsf/core" | ||
xmlns:jsf="http://xmlns.jcp.org/jsf" | ||
encoding="UTF-8"> | ||
|
||
<html> | ||
|
||
<h:head> | ||
|
||
</h:head> | ||
|
||
<!--Main Body --> | ||
<h:body> | ||
|
||
<h1>Welcome to JSF spring boot tutorial</h1> | ||
|
||
<h3>#{jsfBean.welcomeMessage}</h3> | ||
<h3>#{jsfSpringBean.welcomeMessage}</h3> | ||
|
||
</h:body> | ||
|
||
</html> | ||
</f:view> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.levelup; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.test.context.web.WebAppConfiguration; | ||
import org.springframework.boot.test.SpringApplicationConfiguration; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
|
||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@SpringApplicationConfiguration(classes = Application.class) | ||
@WebAppConfiguration | ||
public class ApplicationTests { | ||
|
||
@Test | ||
public void contextLoads() { | ||
} | ||
|
||
} |