Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Thymeleaf设置没有WEB的消息资源_Java_Internationalization_Thymeleaf - Fatal编程技术网

Java Thymeleaf设置没有WEB的消息资源

Java Thymeleaf设置没有WEB的消息资源,java,internationalization,thymeleaf,Java,Internationalization,Thymeleaf,在这个场景中,没有web配置,没有springmvc,没有springboot等等。仅仅是纯应用程序,我想使用Thymeleaf传输静态html资源,并获取字符串中的内容 但是,在这种情况下,如何为thymeleaf设置国际消息?所以我可以在静态html文件中使用 <h1 th:text="#{messageA}">AAAAA</h1> AAAAA 您只需要定义一个消息源。例如,在spring配置中,我有一个主要方法: @Configuration @Component

在这个场景中,没有web配置,没有springmvc,没有springboot等等。仅仅是纯应用程序,我想使用Thymeleaf传输静态html资源,并获取字符串中的内容

但是,在这种情况下,如何为thymeleaf设置国际消息?所以我可以在静态html文件中使用

<h1 th:text="#{messageA}">AAAAA</h1>
AAAAA

您只需要定义一个消息源。例如,在spring配置中,我有一个主要方法:

@Configuration
@ComponentScan(basePackages = {"spring.cli.config"})
public class Main {
    public static void main(String... args) throws Exception {
        ConfigurableApplicationContext spring = new SpringApplicationBuilder(Main.class)
                .web(NONE)
                .profiles("default")
                .run(args);

        TemplateEngine engine = (TemplateEngine) spring.getBean("engine");
        Context context = new Context();
        System.out.println(engine.process("template", context));
    }
}
和一个配置文件(在
@ComponentScan(basePackages={“spring.cli.config”})
中扫描):

我的项目中有一个文件
src/main/resources/messages.properties

# messages.properties
messageA=Hello I am message A
在html中:

<h1 th:text="#{messageA}">AAAAA</h1>
AAAAA
决心:

<div>Hello I am message A</div>
你好,我是一条消息
<div>Hello I am message A</div>