thymeleaf-spring
thymeleaf-spring copied to clipboard
Can't call a @Service bean from Thymeleaf under Spring Boot
BUG
So far I think that what I discovered is a bug
- Thymeleaf (and Thymeleaf Spring): 3.0.11
- Spring Boot 2.1.1
When trying to access said bean I get :
org.springframework.expression.spel.SpelEvaluationException: EL1057E: No bean resolver registered in the context to resolve access to bean 'fileHandling'
In my template I have this piece of code:
<td th:text="${@fileHandling.doSomething()}">...</td>
This is how I prepare Themeleaf (I don't use a Model):
final Context ctx = new Context();
ctx.setVariable("files", map);
ctx.setVariable("fileHandling",fh);
String html = templateEngine.process("flattopic", ctx);
It doesn't make a difference if I setVariable( "fileHandling" ) or not.
The service is defined this way:
@Service
public class FileHandling {
public void doSomething() {
I know that I could make my service static and call it ${T(org.foo.bar.package.FileHandling).doSomething()} but this is much less concise and would force me change the service which I use in a lot of other places.
I asked a similar question on stack overflow and link to it from here.