java - 获取不满意的依赖异常 : while using JSF @Push-annotation with Spring frame work

标签 java spring jsf cdi jsf-2.3

尝试从 Primefaces PUSH 迁移到 JSF Push(Websocket), 在 Java 项目中尝试 JSF Push 时,JSF Push 工作正常。

但是在 Spring 应用程序中尝试时,我得到以下异常

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'pushBean': Unsatisfied dependency expressed through field 'clock'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'javax.faces.push.PushContext' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@javax.inject.Inject(), @javax.faces.push.Push(channel=clock)}

项目结构如下所示。

Project-Structure

下面是我的xml配置

applicationContext.xml

    <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.1.xsd">

    <context:component-scan base-package="com.javatpoint" />

</beans>

beans.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
</beans>

faces-config.xml

<?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>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID" version="3.0">

    <context-param>
        <param-name>javax.faces.ENABLE_WEBSOCKET_ENDPOINT</param-name>
        <param-value>true</param-value>
    </context-param>
    <context-param>
        <param-name>javax.faces.ENABLE_CDI_RESOLVER_CHAIN</param-name>
        <param-value>true</param-value>
    </context-param>
    <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>/faces/*</url-pattern>
    </servlet-mapping>
</web-app>

PushBean.class

@Component
public class PushBean implements Serializable
{
    @Inject
    @Push(channel = "clock")
    private PushContext clock;

    public void clockAction()
    {
        Calendar now = Calendar.getInstance();
        String time = now.get(Calendar.HOUR_OF_DAY) + ":" + now.get(Calendar.MINUTE) + ":" + now.get(Calendar.SECOND);
        clock.send(time);
    }
}

请建议我是否缺少任何配置以解决此问题并使 JSF 推送正常工作?

最佳答案

这篇文章可能会有帮助。 Spring 不将 @Push 注释识别为限定符 https://stackoverflow.com/a/50097928/4519750

关于java - 获取不满意的依赖异常 : while using JSF @Push-annotation with Spring frame work,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54781164/

相关文章:

java - 网站应用程序开发的 richfaces 替代方案

jsf - Primefaces问题: p:filedownload from p:datatable with ViewScoped managed bean

java - 使用 Spring JPA 查询从序列中获取 nextval

java - 带有 @JsonProperty defaultValue 处理的 Jackson 模块

Spring Boot 完整 REST CRUD 示例

java - Spring jdbcTemplate 为空

css - JSF 是如何缓存 CSS 的?

java - 您将如何处理制作一个条目比标准实现允许您访问的条目更多的数组或列表

java - 最大化窗口和布局 channel

java - 使用SVN作为Spring Cloud Config服务器时出错