Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Tip

If you want to test that all routes will be successfully initialized in Camel then use the following test. This test mainly checks that all routes have unique ID and URI.

 

Code Block
/**
 * Test that verifies if all Camel routes are correctly initialized - if there are unique route IDs and unique URIs.
 *
 * @author <a href="mailto:petr.juza@openwise.com">Petr Juza</a>
 */
public class RoutesInitTest extends AbstractModulesDbTest {
    @BeforeClass
    public static void setInitAllRoutes() {
        setInitAllRoutes(true);
    }
    @Test
    public void testInit() {
        // nothing to do - if all routes are successfully initialized then test is OK
        System.out.println("All routes were successfully initialized");
    }
}


Annotation order is important

We use quite often annotations type of @ConditionalXXX or @AutoConfigureAfter/Before. Annotations @ConditionalOnBean/MissingBean/Class/MissingClass works quite fine but @AutoConfigureAfter/Before don't work at all.

Result is that only change in annotation order can go to non-functional or error state. 

Example:

Code Block
public class CamelBootstrapConfiguration {
    // ...

    @Bean
    @ConditionalOnBean(ConnectionFactory.class)
    public CamelContextConfiguration jmsContextConfig(ConnectionFactory factory) {
        // configure jms component
    }

    // ...
}

The following works fine

Code Block
@EnablePlaftormMessaging
@EnableIntegration
public class ApplicationConfiguration {
 // ...
}

... but this doesn't work - it stops during application start because JMS component is not configured. During Camel initialization is not configured messaging and therefore @ConditionalOnBean(ConnectionFactory.class) (use in @EnableXXX annotations) works in different way then we expect.

Code Block
@EnableIntegration
@EnablePlaftormMessaging
public class ApplicationConfiguration {
 // ...
}

Solution

sw


Domnívám se, že by nám prospělo z konfigurací tahaných pomocí @Import udělat autokonfigurace, tzn. předkládat je SpringFactoriesLoaderu přes klíč org.springframework.boot.autoconfigure.EnableAutoConfiguration v META-INF/spring.factories.
To by nám přineslo následující výhody:
Měli bychom k dispozici celou autokonfigurační výzbroj, se kterou lze používat @AutoconfigureAfter/Before. Tím bychom vyřešili problém pořadí konfigurací, respektive synergie frameworků (tzn. převážně Camel + něco)
Mohli bychom zahodit @EnableXXXX anotace, které ve skutečnosti jen obalují anotaci @Import. Konfigurace by byla spuštěna automaticky přes spring.factories podle toho, co má daný projekt v dependencích.
https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-auto-configuration.html
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-developing-auto-configuration.html