使用Jsf视图的Spring Boot

时间:2015-06-10 20:36:08

标签: spring jsf spring-mvc jsf-2 spring-boot

我试图让Spring项目使用jsf视图,我跟着http://www.beyondjava.net/blog/jsf-2-2-primefaces-5-spring-boot/

但由于某种原因,我的根控制器正在返回原始文本而不是页面。基本上这些观点都没有加载。

@SpringBootApplication
public class MySpringAppApplication extends SpringBootServletInitializer {
    private static final Logger logger = LoggerFactory.getLogger(MySpringAppApplication.class);

    public static void main(String[] args)  {
         SpringApplication.run(MySpringAppApplication.class, args);
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(MySpringAppApplication.class, JsfInitializer.class);
    }

    // servlet to run jsf stuff
    @Bean
    public ServletRegistrationBean servletRegistrationBean() {
        FacesServlet servlet = new FacesServlet();
        ServletRegistrationBean servletRegistrationBean = new  ServletRegistrationBean(servlet, "*.jsf");

        return servletRegistrationBean;
    }

}

并在我的根控制器中,返回" index"只返回该字符串

@RestController
public class RootController {
    private MailSender mailSender;

    @Autowired
    RootController(MailSender mailSender) {
        this.mailSender = mailSender;
    }

    // @ResponseBody --not needed with @RestController
    @RequestMapping("/")
    public String home() throws MessagingException {

    //  mailSender.send("franklin@gmail.com", "programming", "how are you on that project?");
        return "index";
    }

}

index.xhtml in in the WebContent dir





public class JsfInitializer implements ServletContextInitializer{

    @Override
    public void onStartup(ServletContext servletContext) throws ServletException {
        servletContext.setInitParameter("primefaces.CLIENT_SIDE_VALIDATION", "true");
        servletContext.setInitParameter("javax.faces.PROJECT_STAGE", "Development");

    }

}

并在faces.config中:

  <application>
        <el-resolver>
                org.springframework.web.jsf.el.SpringBeanFacesELResolver
        </el-resolver>
    </application>

没有web.xml文件

0 个答案:

没有答案