2017-05-05 31 views
0

我有一个基本的SpringBoot应用程序,嵌入式Tomcat,Thymeleaf模板引擎,以及作为可执行JAR文件的包。Spring Boot配置类未调用

我有这个主类

package com.tdk.iot; 

@SpringBootApplication 
@Import({SecurityConfig.class }) 
public class TdkApplication { 

    public static void main(String[] args) { 
     SpringApplication.run(TdkApplication.class, args); 
    } 
} 

而这一次

package com.tdk.iot.config; 

    @Configuration 
    @Profile("dev") 
    @PropertySource("file:///${user.home}/.tdk/application-dev.properties") 
    public class DevelopmentConfig { 

     @Bean 
     public EmailService emailService() { 
      return new MockEmailService(); 
     } 

     @Bean 
     public ServletRegistrationBean h2ConsoleServletRegistration() { 

      ServletRegistrationBean bean = new ServletRegistrationBean(new WebServlet()); 
      bean.addUrlMappings("/console/*"); 
      return bean; 
     } 
    } 

,并在application.properties这个值:

spring.profiles.active=dev 

但似乎因为不工作我无法进入页面/console/*

+0

您确定您的'''DevelopmentConfig' bean是由spring config加载吗? – Sigrist

+0

您确定应用程序启动的目录还包含.tdk文件夹吗?因为“user.home”不是OS用户主目录,而是JVM启动的目录。 –

+0

我不这么认为,我不知道为什么 –

回答

0

我发现了错误。在eclipse - > Run配置 - >参数中,数值也被其他值覆盖

-Dspring.profiles.active=acc 
0

您应该将@PropertySource移动到您的SecurityConfig或TdkApplication类中,因为您尝试在类中加载配置文件属性“dev”,仅当配置文件为“dev”时才会将其包含在上下文中 - 因此Spring无法加载属性文件。

相关问题