logo
down
shadow

Spring more than one profile and ${spring.profiles.active}


Spring more than one profile and ${spring.profiles.active}

By : user2956308
Date : November 22 2020, 10:54 AM
I wish did fix the issue. In spring 4.1.2.RELEASE, we have 2 active profiles in web.xml , This did the job:
code :
<util:properties id="signConditions"
        location="classpath:/configs/#{environment.getActiveProfiles()[1]}/sample.properties" />


Share : facebook icon twitter icon
how to add active profile to spring in conjuction with spring's spring.profiles.active

how to add active profile to spring in conjuction with spring's spring.profiles.active


By : 沈泉梁
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further We do have some spring profiles enables via web.xml spring.profiles.active and I want to leave it that way as this is the way for our deployment team to activate profiles. in addition I want to activate some more profiles based on the presence of properties files. so I added an ApplicationContextInitializer , Can you use:
code :
profiles = ac.getEnvironment().getActiveProfiles()
ac.getEnvironment().setActiveProfiles(profiles, "profileName")
What is the order of precedence when there are multiple Spring's environment profiles as set by spring.profiles.active

What is the order of precedence when there are multiple Spring's environment profiles as set by spring.profiles.active


By : Tschico
Date : March 29 2020, 07:55 AM
it helps some times The order of the profiles in the spring.profiles.active system property doesn't matter. "Precedence" is defined by the declaration order of the beans, including beans specific to a profile, and the last bean definition wins.
Using your example, if -Dspring.profiles.active="default,dev" is used, the props bean in the default profile would be used here, simply because it's the last active definition of that bean:
code :
<beans profile="dev">
    <bean id="props" class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
        <property name="location" value="classpath:META-INF/dev.properties"/>
    </bean>
</beans>
<beans profile="default">
    <bean id="props" class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer">
        <property name="location" value="classpath:META-INF/default.properties"/>
    </bean>
</beans>
what is the Difference between spring.profiles.active=production vs spring.profiles.active=local

what is the Difference between spring.profiles.active=production vs spring.profiles.active=local


By : Vlad
Date : March 29 2020, 07:55 AM
Does that help Certain environment-specific choices made for development aren’t appropriate or won’t work when the application transitions from development to production.
Consider database configuration, for instance. In a development environment, you’re likely to use an embedded database preloaded with test data like this:
code :
@Bean(destroyMethod="shutdown")
public DataSource dataSource() {
    return new EmbeddedDatabaseBuilder()
    .addScript("classpath:schema.sql")
    .addScript("classpath:test-data.sql")
    .build();
}
@Bean
public DataSource dataSource() {
    JndiObjectFactoryBean jndiObjectFactoryBean = new JndiObjectFactoryBean();
    jndiObjectFactoryBean.setJndiName("jdbc/myDS");
    jndiObjectFactoryBean.setResourceRef(true);
    jndiObjectFactoryBean.setProxyInterface(javax.sql.DataSource.class);
    return (DataSource) jndiObjectFactoryBean.getObject();
}
@Configuration
public class DataSourceConfig {
    @Bean(destroyMethod="shutdown")
    @Profile("development")
    public DataSource embeddedDataSource() {
        return new EmbeddedDatabaseBuilder()
        .setType(EmbeddedDatabaseType.H2)
        .addScript("classpath:schema.sql")
        .addScript("classpath:test-data.sql")
        .build();
    }

    @Bean
    @Profile("production")
    public DataSource jndiDataSource() {
        JndiObjectFactoryBean jndiObjectFactoryBean = new JndiObjectFactoryBean();
        jndiObjectFactoryBean.setJndiName("jdbc/myDS");
        jndiObjectFactoryBean.setResourceRef(true);
        jndiObjectFactoryBean.setProxyInterface(javax.sql.DataSource.class);
        return (DataSource) jndiObjectFactoryBean.getObject();
    }
}
@Profile does not work without Spring Boot (-Dspring.profiles.active with maven)

@Profile does not work without Spring Boot (-Dspring.profiles.active with maven)


By : alex
Date : March 29 2020, 07:55 AM
wish help you to fix your issue The Spring profiles are for running your appplication, not building. Pass the -Dspring.profiles.active=env when you execute your application. In your example you are doing a mvn install which does not execute your application.
spring.profiles.active priority for application-{profile}.properties

spring.profiles.active priority for application-{profile}.properties


By : Pako Magdaleno
Date : March 29 2020, 07:55 AM
like below fixes the issue According to the documentation, the last profile specified wins.
In your example : spring.profiles.active=profile1,profile2, the properties of profile2 should overwrite the properties of profile1.
Related Posts Related Posts :
  • Autowired not happening for bean with @Async method
  • Spring Framework does not required sever. Is it true?
  • How to implement Generics DAO with Spring JDBC template
  • Escaping a | (pipe) in SpEL
  • Spring: Using @Qualifier with Property Placeholder
  • abount the singleton beans of spring
  • Spring @Autowired Not Working Error Creating Bean Injection Of Autowire dependencies failed
  • Spring-MVC Exception handler returns OK when writing into response
  • My applicationContext.xml is not valid when i deploy my project on tomcat7:org.springframework.beans.factory.parsing.Bea
  • Storing trailing zeroes in database with JPA and Oracle
  • Making specific method non transactional in Spring
  • Spring Batch - interrupt thread when job stops
  • Can I use spring AOP to log start and end of a method to help easy debuging
  • How to use different error codes for validation messages?
  • Spring Data Rest and collections with unique constraints
  • Thymeleaf + Spring Checkboxes not binding
  • Spring Boot: Publish Thymeleaf template without restarting the server
  • How long will Spring 3.x continue to be supported?
  • Spring Security without a login form
  • SOAP UI not finding WSDL depending XSD files in Spring WS Soap Service
  • Spring MVC- Joda datetime error message for invalid date
  • Broadleaf Demosite on JBOSS 7
  • Spring Mongo mapping variable data
  • MySQL and Infinispan - JTA implementation
  • spring boot autoconfiguration with jdbc template autowiring dataSource issue
  • Hibernate and @SessionAttribute
  • DefaultMessageListenerContainer threading issue
  • Good sample spring and hibernate web application book?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org