Spring Boot JSF 一体化
环境 :
Tomcat 8
Spring Boot 1.5
JSF 2.2
Apache MyFaces
Spring MVC
代码 :
我整合了 Spring Boot 和 JSF 2.2 在星期三 Servlet 3.0.
配置类 :
jsfconfig.java配置 JSF.
Spring Boot 主班 :
管理鲍勃 :
userbean.java-managed bean for JSF
其他 :
home.xhtml-homepage.
person-config.xml. :
问题 :
1/ 当我发送形式
, 我叫我。
2/
获取用户输入的一组值。
3/ 但
- 这是 NULL.
4/ 这是否意味着 Spring 和 JSF 不要整合 ? 我也注册了
, 如提到的B.
我也试图删除一切 JSF 具体的注释 UserBean.java 只使用 Spring 具体的注释,如下所示 -
但是当我发送形式时,我弄错了 target Unreachable 为了
. 代表着
未检测到 Spring
5/ 我不错过任何东西 ?
6/我不使用内置的 tomcat, 提供的S. Spring Boot
Tomcat 8
Spring Boot 1.5
JSF 2.2
Apache MyFaces
Spring MVC
代码 :
我整合了 Spring Boot 和 JSF 2.2 在星期三 Servlet 3.0.
配置类 :
jsfconfig.java配置 JSF.
@Configuration
@ComponentScan/{"com.atul.jsf"}/
public class JSFConfig {
@Bean
public ServletRegistrationBean servletRegistrationBean// {
FacesServlet servlet = new FacesServlet//;
return new ServletRegistrationBean/servlet, "*.jsf"/;
}
}
Spring Boot 主班 :
@SpringBootApplication
@Import/{ // @formatter:off
JPAConfig.class,
ServiceConfig.class, // this contains UserServiceImpl.java class.
WebConfig.class,
JSFConfig.class,
}/
public class SpringbootJpaApplication extends SpringBootServletInitializer{
public static void main/String[] args/ {
SpringApplication.run/SpringbootJpaApplication.class, args/;
}
@Override
protected SpringApplicationBuilder configure/SpringApplicationBuilder application/ {
return application.sources/SpringbootJpaApplication.class/;
}
}
管理鲍勃 :
userbean.java-managed bean for JSF
@ManagedBean
@SessionScoped
public class UserBean implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private String name;
@ManagedProperty/value="#{userServiceImpl}"/
private UserServiceImpl userServiceImpl;
public void addUser//{
System.out.println/"User Gets added "+this.name/;
}
public String getName// {
return name;
}
public void setName/String name/ {
this.name = name;
}
public UserServiceImpl getUserServiceImpl// {
return userServiceImpl;
}
public void setUserServiceImpl/UserServiceImpl userServiceImpl/ {
this.userServiceImpl = userServiceImpl;
}
}
其他 :
home.xhtml-homepage.
xml version="1.0" encoding="UTF-8"?
html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"[url=http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"]http://www.w3.org/TR/xhtml1/DT ... ot%3B[/url]
<html xmlns="[url=http://www.w3.org/1999/xhtml"]http://www.w3.org/1999/xhtml"[/url] xmlns:f="[url=http://java.sun.com/jsf/core"]http://java.sun.com/jsf/core"[/url] xmlns:h="[url=http://java.sun.com/jsf/html">]http://java.sun.com/jsf/html">[/url]
<h:head>
<title>JSF 2.0 Hello World</title>
</h:head>
<h:body>
<h2>JSF 2.0 Hello World Example - hello.xhtml</h2>
<h:form>
<h:inputtext value="#{userBean.name}"></h:inputtext>
<h:commandbutton action="#{userBean.addUser}" value="Submit"></h:commandbutton>
</h:form>
</h:body>
</html>
person-config.xml. :
xml version="1.0" encoding="UTF-8"?
<faces-config version="2.2" xmlns="[url=http://xmlns.jcp.org/xml/ns/javaee"]http://xmlns.jcp.org/xml/ns/javaee"[/url] xmlns:xsi="[url=http://www.w3.org/2001/XMLSchema-instance"]http://www.w3.org/2001/XMLSchema-instance"[/url] xsi:schemalocation="[url=http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd">]http://xmlns.jcp.org/xml/ns/ja ... gt%3B[/url]
<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>
问题 :
1/ 当我发送形式
home.xhtml , userBean.addUser
, 我叫我。
2/
userBean.name
获取用户输入的一组值。
3/ 但
userServiceImpl
- 这是 NULL.
4/ 这是否意味着 Spring 和 JSF 不要整合 ? 我也注册了
SpringBeanFacesELResolver
, 如提到的B.
faces-config.xml
我也试图删除一切 JSF 具体的注释 UserBean.java 只使用 Spring 具体的注释,如下所示 -
@Component
@SessionScoped
public class UserBean implements Serializable{
/**
*
*/
private static final long serialVersionUID = 1L;
private String name;
@Autowired
private UserServiceImpl userServiceImpl;
}
但是当我发送形式时,我弄错了 target Unreachable 为了
#{userBean/
. 代表着
userBean
未检测到 Spring
5/ 我不错过任何东西 ?
6/我不使用内置的 tomcat, 提供的S. Spring Boot
没有找到相关结果
已邀请:
1 个回复
八刀丁二
赞同来自:
https://github.com/xtremebiker/jsf-spring-boot
/:
1. 依赖性
除了标准依赖 web starter 你需要打开 tomcat embedded jasper, 如所提供的那样标记 /谢 @Fencer 对于评论
/. 否则,您将在申请开始时出现异常 JSF 取决于处理器 JSP /另请参阅答案结束时的第一个链接。/.
2. 注册servlet.
注册servlet. JSF 并在启动时调整它以下载 /不需要 web.xml/. 在工作时。 JSF 2.2 最佳使用映射
, 至少在使用方面时:
使您的配置类实现
https://docs.spring.io/spring- ... .html
因此,您可以设置初始化设置。 在这里,你必须强迫 JSF 下载配置:
3. EL 一体化
调整
https://docs.spring.io/spring- ... .html
EL 在faces config.xml中。 它将是您的演示文稿文件和您的托管属性和Bob方法之间的链接:
4. 审查区
写一个自定义区域 Spring 模仿演示区域 JSF /请记住,您的豆类将被管理 Spring, 但不是 JSF/. 它应该看起来像这样:
并在配置类中注册它:
5. 准备工作!
现在,您可以如下声明托管豆。 不要忘记使用
/优选地,在构造师中/ 反而
, 因为你处理 Spring 鲍勃。
仍然没有实现
我无法强迫 JSF 具体的注释在上下文中工作 Spring Boot. 因此 ,
,
,
等等不能使用。 但是,有机会在人员中声明它们 - config.xml /厘米。
http://xmlns.jcp.org/xml/ns/ja ... 2.xsd
/, 老式的方式。
也可以看看
:
https://coderoad.ru/25479986/
https://www.primefaces.org/por ... -3-0/
https://coderoad.ru/20602010/
Spring Boot
</string,></string,>