1

I have @SpringBootApplication with @ComponentScan({"myPackage"}) and in myPackage I have a class annotated with @Configuration or @Component. When I start the spring boot app the logs show:

DEBUG [main] org.sprin.conte.annot.ClassPathScanningCandidateComponentProvider 437 scanCandidateComponents: Identified candidate component class: file [C:\Web\project\bin\main\myPackage\Config.class]

but then nothing injects the class or its beans into the app...

It looks related to this

CODE

package app;

import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.LogManager;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.gemfire.config.annotation.EnableLogging;
import org.springframework.data.gemfire.repository.config.EnableGemfireRepositories;

@SpringBootApplication
@ComponentScan({"myPackage"})
@EntityScan({"myPackage"})
@EnableGemfireRepositories("region") 
@EnableLogging(logLevel="info", logFile="geodeApi.log")
public class Web {

    private static final Logger log = LogManager.getLogger(Web.class);

    public static void main(String[] args) {
        log.info("In Main");

        SpringApplication app = new SpringApplication(Web.class);
        app.setWebApplicationType(WebApplicationType.REACTIVE);
        SpringApplication.run(Web.class, args);

        log.info("Out Main");
    }
}

In myPackage.Client

package myPackage;

import java.util.UUID;

import javax.annotation.PreDestroy;
import javax.annotation.Resource;

import org.apache.logging.log4j.Logger;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.client.ClientRegionShortcut;
import org.apache.logging.log4j.LogManager;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.data.gemfire.cache.config.EnableGemfireCaching;
import org.springframework.data.gemfire.config.annotation.ClientCacheApplication;
import org.springframework.data.gemfire.config.annotation.EnableClusterDefinedRegions;
import org.springframework.data.gemfire.config.annotation.EnablePdx;
import org.springframework.data.gemfire.config.annotation.EnablePool;
import org.springframework.data.gemfire.config.annotation.EnablePool.Locator;
import org.springframework.data.gemfire.config.annotation.EnableStatistics;
import org.springframework.session.data.gemfire.config.annotation.web.http.EnableGemFireHttpSession;

@ClientCacheApplication(name = "Web", logLevel = "debug")
@EnablePool(name = "webPool", subscriptionEnabled = true)
@EnableClusterDefinedRegions(clientRegionShortcut=ClientRegionShortcut.CACHING_PROXY)
@EnablePdx
@EnableStatistics
@EnableGemFireHttpSession(poolName = "webPool")
@EnableGemfireCaching
// @EnableWebFlux
public class Client {

    private static final Logger log = LogManager.getLogger(Client.class);

    @Resource
    private Region<String, String> myAdmin;

    @PreDestroy
    public void onDestroy() throws Exception {

        log.info("onDestroy");

        String guid = UUID.randomUUID().toString().substring(0, 8).toUpperCase();           
        myAdmin.put(guid, "Web Shutdown");

        log.traceExit();
    }

    @Bean
    ApplicationRunner StartedUp(){      
        log.traceEntry("StartedUp");

        return args -> {            
        String guid = UUID.randomUUID().toString().substring(0, 8).toUpperCase();       
        myAdmin.put(guid, "Web Started");

        log.traceExit();
        };
    }

    // Required to resolve property placeholders in Spring @Value annotations.
    @Bean
    static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() {
        log.traceEntry("propertyPlaceholderConfigurer");
        return new PropertySourcesPlaceholderConfigurer();
    }
}

In myPackage.Config

package myPackage;

import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.client.ClientRegionShortcut;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.gemfire.client.ClientRegionFactoryBean;

@Configuration
public class Config {
    private static final Logger log = LogManager.getLogger(Config.class);

@Bean("myRegion")
public Region<String, Object> myRegion(GemFireCache cache) {
    log.traceEntry();

    Region<String, Object> r = cache.getRegion("myRegion");
    r.setUserAttribute(ClientRegionShortcut.CACHING_PROXY);

    return r;
    }
}
rupweb
  • 3,052
  • 1
  • 30
  • 57

1 Answers1

1

In Config class while defining the bean you are using Region<String, Object> as return type. Where as in the your Client class you define Region<String, String>. Here it is clearly a type mismatch and hence bean will not load.

  • well, no that’s another region “myAdmin” used for put and get admin messages. I’m looking to setup another “myRegion” region as a bean, to later subscribe & unsubscribe to interesting events..... – rupweb Feb 13 '20 at 21:06
  • 1
    Can you run spring app with debug enabled and see what the AUTO-CONFIGURATION REPORT says and check If spring maps `myRegion` to `Region`? Posting the report here would also help. – Deepak Kharpuriya Feb 14 '20 at 07:51