当我尝试从视图调用方法时遇到问题。
我的 Java 类与方法
public class FuncionesMuestroteca {
@Bean
public static boolean estoyMuestroteca() {
boolean resultado = false;
return resultado;
}
}
Run Code Online (Sandbox Code Playgroud)
现在我从 header.html 调用函数
<th:block th:text="${FuncionesMuestroteca.estoyMuestroteca()}"/>
Run Code Online (Sandbox Code Playgroud)
在 POM.xml 中,我导入了 thymeleaf-extras 版本 2.1.0.RELEASE 和 thymeleaf 2.1.5
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
<version>2.1.0.RELEASE</version>
Run Code Online (Sandbox Code Playgroud)
这里是 StackTrace
org.springframework.expression.spel.SpelEvaluationException: EL1011E: Method call: Attempted to call method estoyMuestroteca() on null context object
Run Code Online (Sandbox Code Playgroud)
如果您需要其他任何东西,请不要犹豫,告诉我,我会放的。先感谢您。
新的堆栈跟踪:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'estoyMuestroteca' available
Run Code Online (Sandbox Code Playgroud)
HTML 编辑
<div th:text="${@estoyMuestroteca.estoyMuestroteca()}"></div>
Run Code Online (Sandbox Code Playgroud)
方法实际
@Configuration
public class FuncionesMuestroteca {
@Bean(name = "estoyMuestroteca")
public boolean estoyMuestroteca() {
boolean …Run Code Online (Sandbox Code Playgroud)