I am trying to integrate facelets with my Spring. I tried the folowing configuration but getting following error
SEVERE: Servlet.service() for servlet [springWebDispatcher] in context with path [/LS360ProxyAPIWeb] threw exception [Request processing failed; nested exception is javax.faces.FacesException: /WEB-INF/jsf/viewlogin.xhtml Not Found in ExternalContext as a Resource] with root cause
com.sun.faces.context.FacesFileNotFoundException: /WEB-INF/jsf/viewlogin.xhtml Not Found in ExternalContext as a Resource
Here what I did. First I added following maven dependencies to my project
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.12</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.12</version>
</dependency>
<dependency>
<groupId>org.springframework.webflow</groupId>
<artifactId>spring-faces</artifactId>
<version>2.4.2.RELEASE</version>
</dependency>
Then I added following lines in my startup
@Order(1)
public class FrameworkBootstrap implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext container) throws ServletException {
container.getServletRegistration("default").addMapping("/resource/*");
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.register(RootContextConfiguration.class);
container.addListener(new ContextLoaderListener(rootContext));
container.addListener(new RequestContextListener());
AnnotationConfigWebApplicationContext webContext = new AnnotationConfigWebApplicationContext();
webContext.register(WebServletContextConfiguration.class);
ServletRegistration.Dynamic dispatcher = container.addServlet("springWebDispatcher", new DispatcherServlet(webContext));
dispatcher.setLoadOnStartup(1);
dispatcher.setMultipartConfig(new MultipartConfigElement(null, 20_971_520L, 41_943_040L, 512_000));
dispatcher.addMapping("/");
container.setInitParameter("javax.faces.DEFAULT_SUFFIX", ".xhtml");
container.getServletRegistration("FacesServlet").addMapping("*.xhtml");
AnnotationConfigWebApplicationContext restContext = new AnnotationConfigWebApplicationContext();
....
AnnotationConfigWebApplicationContext soapContext = new AnnotationConfigWebApplicationContext();
...
}
}
In my WebServletContextConfiguration class I added the following view Resolver
@Configuration
@EnableWebMvc
@ComponentScan(
basePackageClasses = {WebControllerMarker.class},
useDefaultFilters = false,
includeFilters = @ComponentScan.Filter(WebController.class)
)
public class WebServletContextConfiguration extends WebMvcConfigurerAdapter {
....
/**
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setViewClass(JstlView.class);
resolver.setPrefix("/WEB-INF/jsp/view/");
resolver.setSuffix(".jsp");
return resolver;
}
*/
@Bean
public UrlBasedViewResolver faceletViewResolver() {
UrlBasedViewResolver resolver = new UrlBasedViewResolver();
resolver.setViewClass(JsfView.class);
resolver.setPrefix("/WEB-INF/jsf/view");
resolver.setSuffix(".xhtml");
return resolver;
}
....
}
I uncommented my JSP view. JSP view works fine when application runs. I also have spring security In my rootcontext.
@Configuration
@EnableLoadTimeWeaving
@ComponentScan(..)
@Import({SecurityConfiguration.class, ...})
public class RootContextConfiguration {
....
}
Spring Security
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(
prePostEnabled = true,
order = 0,
mode = AdviceMode.PROXY,
proxyTargetClass = false
)
public class SecurityConfiguration {
@Configuration
@ComponentScan(basePackageClasses = {FilterMarker.class})
@Order(1)
public static class RestApiWebSecurityConfigurationAdapter extends WebSecurityConfigurerAdapter {
....
}
@Configuration
public static class FormLoginWebSecurityConfigurerAdapter extends WebSecurityConfigurerAdapter {
@Override
public void configure(WebSecurity security) {
security.ignoring().antMatchers("/resources/**");
}
@Override
protected void configure(HttpSecurity security) throws Exception {
security
.authorizeRequests()
.antMatchers("/sso/cas/lf/**").hasAuthority("ROLE_ANONYMOUS")
// Any request simply requires authentication, regardless of permissions.
.anyRequest()
.authenticated()
.and()
.formLogin()
.loginPage("/login")
.loginProcessingUrl("/j_spring_security_check" )
.failureUrl("/login?loginFailed")
.defaultSuccessUrl("/interceptor.do")
.usernameParameter("username")
.passwordParameter("password")
.permitAll()
.and()
.logout()
.logoutUrl("/logout")
.logoutSuccessUrl("/login?loggedOut")
.invalidateHttpSession(true)
.deleteCookies("JSESSIONID")
.permitAll()
.and()
.sessionManagement()
.sessionFixation()
.changeSessionId()
.maximumSessions(1)
.maxSessionsPreventsLogin(true)
.sessionRegistry(this.sessionRegistryImpl())
.and()
.and()
.csrf()
.disable();
}
}
I added following faces-config.xml in my WEB-INF
<?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 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>
</faces-config>
I added following login.xhtml page in my WEB-INF/jsf/view/login.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>JSF Spring Integration Example</title>
</h:head>
<h:body>
<h3>Item Master</h3>
</h:body>
</html>
Then I ran my project but getting error. What I am doing wrong and what I am missing ?
Thanks