Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't call a @Service bean from Thymeleaf under Spring Boot #201

Open
mar1ged opened this issue Dec 16, 2018 · 0 comments
Open

Can't call a @Service bean from Thymeleaf under Spring Boot #201

mar1ged opened this issue Dec 16, 2018 · 0 comments

Comments

@mar1ged
Copy link

mar1ged commented Dec 16, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant