Spring-boot如何导入所有jar dependdencys项目的所有i18n消息?

时间:2017-05-18 21:21:36

标签: java spring maven spring-boot internationalization

我想导入所有messages.properties文件,这些文件包含在我项目的所有jar依赖项的src / main / resource / messages位置中。 例如: 项目A导入 - >项目B,我需要加载所有消息属性。

我试过了:

@Bean
public ReloadableResourceBundleMessageSource messageSource() {
  ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
  messageSource.setBasenames("classpath:/messages", "classpath:/messages/messages");
  messageSource.setCacheSeconds(3600);
  return messageSource;
}

但它不起作用=(。我怎么能用spring-boot做到这一点?

这是我的项目结构:

project A
+-- project-server-business
¦   +-- src
¦   ¦   +-- main
¦   ¦   ¦   +-- java
¦   ¦   ¦   +-- resources
¦   ¦   ¦   ¦   +-- messages
¦   ¦   ¦   ¦   ¦  +-- messages-business.properties
¦   +-- pom.xml
+-- project-server-service
¦   +-- src
¦   ¦   +-- main
¦   ¦   ¦   +-- java
¦   ¦   ¦   +-- resources
¦   ¦   ¦   ¦   +-- messages
¦   ¦   ¦   ¦   ¦  +-- messages-business.properties
¦   +-- pom.xml
+-- pom.xml

project B
+-- project-server-business
¦   +-- src
¦   ¦   +-- main
¦   ¦   ¦   +-- java
¦   ¦   ¦   +-- resources
¦   ¦   ¦   ¦   +-- messages
¦   ¦   ¦   ¦   ¦  +-- messages-business.properties
¦   +-- pom.xml
+-- project-server-service
¦   +-- src
¦   ¦   +-- main
¦   ¦   ¦   +-- java
¦   ¦   ¦   +-- resources
¦   ¦   ¦   ¦   +-- messages
¦   ¦   ¦   ¦   ¦  +-- messages-business.properties
¦   +-- pom.xml
+-- pom.xml

我的pom构建结构:

<build>

        <resources>
            <resource>
                <directory>src${file.separator}main${file.separator}resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>

        <pluginManagement>
            <plugins>   
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <version>${spring.boot.version}</version>
                    <configuration>
                        <source>${maven.plugin.target}</source>
                        <target>${maven.plugin.target}</target>
                        <failOnMissingWebXml>false</failOnMissingWebXml>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>${maven.war.plugin.version}</version>
                </plugin>

                <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-compiler-plugin</artifactId>
                  <version>${maven.compiler.plugin.version}</version>
                  <configuration>
                    <source>${maven.plugin.target}</source>
                    <target>${maven.plugin.target}</target>
                  </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
  </build>

0 个答案:

没有答案