eccomi qua!
allora, ho modificato il main levando i bean:
codice:
package com.example.test_springboot_java;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class TestSpringbootJavaApplication {
public static void main(String[] args) {
SpringApplication.run(TestSpringbootJavaApplication.class, args);
}
}
a questo punto ho creato un file messages.properties e un messages_en.properties sotto resources.
e nell'application.properties:
codice:
spring.messages.basename=messages, config.i18n.messages
spring.messages.common-messages=classpath:my-common-messages.properties
spring.messages.fallback-to-system-locale=false
nel controller poi ho fatto così:
codice:
package com.example.test_springboot_java.controllers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import java.util.Locale;
@RestController
@RequestMapping(path = "/test")
public class TestController {
@Autowired
MessageSource messageSource;
@GetMapping(path = "/{lingua}", produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public String index(@PathVariable Locale lingua) {
System.out.println(lingua);
return messageSource.getMessage("saluti", null, lingua);
}
}
sembra funzionare tutto, grazie!!