简体   繁体   中英

Spring swallow exception during startup

I have bean (don't mind try catch it is for debug purpose):

    @Bean
    public IgniteEntityConfiguration articleIgniteEntityConfig() {
        try {
            return IgniteEntityConfiguration.builder()
                    .cacheName("ArticleCache")
                    .dbTableName("ARTICLE")
                    .valueClass(Article.class)
                    .build();
        } catch (Exception e) {
            log.error("bean errr", e);
            throw e;
        }

    }

In IgniteEntityConfiguration I validate passed class and thrown exception if needed.

flow

In logs I have:

  1. Error logged by logger log.error("bean errr", e); ;
  2. Other info lines.
  3. Error from @Controller that is using bean that intercity uses articleIgniteEntityConfig ; And here app stops .

If I delete try catch block, the error is not even logged (exception is thrown - I checked it with debugger).

question

Why is that? Shouldn't the first exception in beans stop the app?

I found the answer. I don't get meaningful error because in IgniteRepositoryFactory (ignite-spring-data_2.2) all cause errors are swallowed and only this error is thrown:

                    throw new IgniteException("Failed to initialize Ignite repository factory. Ignite instance or"
                        + " IgniteConfiguration or a path to Ignite's spring XML "
                        + "configuration must be defined in the"
                        + " application configuration");

full method

 private Ignite igniteForRepoConfig(RepositoryConfig config) {
        try {
            String igniteInstanceName = evaluateExpression(config.igniteInstance());
            return (Ignite)ctx.getBean(igniteInstanceName);
        }
        catch (BeansException ex) {
            try {
                String igniteConfigName = evaluateExpression(config.igniteCfg());
                IgniteConfiguration cfg = (IgniteConfiguration)ctx.getBean(igniteConfigName);
                try {
                    // first try to attach to existing ignite instance
                    return Ignition.ignite(cfg.getIgniteInstanceName());
                }
                catch (Exception ignored) {
                    // nop
                }
                return Ignition.start(cfg);
            }
            catch (BeansException ex2) {
                try {
                    String igniteSpringCfgPath = evaluateExpression(config.igniteSpringCfgPath());
                    String path = (String)ctx.getBean(igniteSpringCfgPath);
                    return Ignition.start(path);
                }
                catch (BeansException ex3) {
                    throw new IgniteException("Failed to initialize Ignite repository factory. Ignite instance or"
                        + " IgniteConfiguration or a path to Ignite's spring XML "
                        + "configuration must be defined in the"
                        + " application configuration");
                }
            }
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM