Spring boot Can';t在jsf中从表达式语言访问get方法

Spring boot Can';t在jsf中从表达式语言访问get方法,spring-boot,jsf,primefaces,Spring Boot,Jsf,Primefaces,我无法通过访问xhtml代码中的getCpuUsage()方法 <h:outputText id="cpu_usage" value="#{cpuUsageBean.cpuUsage} %" /> 如果不进行投票,它会起作用吗?有错误吗?是的,很遗憾。当我将getCpuUsage()方法视为bean时,它显示“java.lang.IllegalStateException:找不到工厂备份”错误。但如果我删除bean注释,则不会显示任何错误。但

我无法通过访问xhtml代码中的getCpuUsage()方法

<h:outputText id="cpu_usage"
                    value="#{cpuUsageBean.cpuUsage} %" />

如果不进行投票,它会起作用吗?有错误吗?是的,很遗憾。当我将getCpuUsage()方法视为bean时,它显示“java.lang.IllegalStateException:找不到工厂备份”错误。但如果我删除bean注释,则不会显示任何错误。但是正如我所说的,我们无法通过netither#{语言或${}访问getCpuUsage()方法。我在网上尝试了web.xml或faces.config技巧,但没有一个解决了我的问题。为什么问题中缺少此错误?你是否尝试将此错误放在搜索引擎中?今年我尝试了stackoverflow中的lpts Q/a。我知道有重复的问题。我也看到了你的评论。但正如我所说,没有一个与@bea一起工作n注释。我的问题与@bean无关。我的问题是无法从xhtml访问属性,因此xhtml无法正确呈现。您是否使用JoinFaces?如果没有,我认为您需要使Spring Boot+JSF正常工作。因为我正在查看您的注释,它们是错误的。请参阅
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui">

<h:head></h:head>
<h:body style="margin-left:50px">
    <h2>PrimeFaces Polling Example</h2>
    <h:form>
        CPU usage:
        <b> <h:outputText id="cpu_usage"
                value="#{cpuUsageBean.cpuUsage} %" />
        </b>
    <p:poll interval="1" update="cpu_usage" /> 
    </h:form>
</h:body>
</html>
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import javax.annotation.PostConstruct;
import javax.faces.bean.ViewScoped;
import javax.inject.Inject;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Scope;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.InitBinder;

import lombok.extern.slf4j.Slf4j;


@Component
@Scope("VIEW")
//@ViewScoped
//@Named
@Slf4j
public class CpuUsageBean {

    private AtomicInteger cpuUsage;

    @PostConstruct
    public void init() {
        cpuUsage = new AtomicInteger(50);
        ExecutorService es = Executors.newFixedThreadPool(1);
        es.execute(() -> {
            while (true) {
                // simulating cpu usage
                int i = ThreadLocalRandom.current().nextInt(-10, 11);
                int usage = cpuUsage.get();
                usage += i;
                if (usage < 0) {
                    usage = 0;
                } else if (usage > 100) {
                    usage = 100;
                }
                cpuUsage.set(usage);
                try {
                    TimeUnit.MILLISECONDS.sleep(500);
                } catch (InterruptedException e) {
                }
            }
        });
    }


    public int getCpuUsage() {
        System.out.println("-----getCpuUsage : " + cpuUsage);
        log.error("---------- getCpuUsage calisti");
        return cpuUsage.get();
    }
}
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

    @SpringBootApplication
    @ComponentScan(basePackages = "com.tutorial.PrimeFacesTutorial.controller,com.tutorial.PrimeFacesTutorial")
    public class PrimeFacesTutorialApplication {

        public static void main(String[] args) {
            SpringApplication.run(PrimeFacesTutorialApplication.class, args);
        }

    }