0

I am trying out a spring boot app with REST web services. I plan to use multiple instances of the same app and hence registered them as Eureka client. I have used load balacing with Zuul. This works fine. Now when I tried to add Hezelcast to the app instances, the app comes up but the hazelcast instance does not. I am stuck as to why it would not. Any help is appreciated.

This is my config class.

@Configuration
public class CacheConfig {

    @Bean
    public Config config() {            
        return new Config();
    }

}

And these are my pom dependencies.

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-security</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka</artifactId>    
        <version>1.1.5.RELEASE</version>        
    </dependency>
    <dependency>
        <groupId>com.hazelcast</groupId>
        <artifactId>hazelcast</artifactId>          
    </dependency>   
    <dependency>
        <groupId>com.oracle</groupId>
        <artifactId>ojdbc6</artifactId>
        <version>11.2.0.3.0</version>
    </dependency>
    <dependency>
        <groupId>io.jsonwebtoken</groupId>
        <artifactId>jjwt</artifactId>
        <version>0.6.0</version>
    </dependency>
    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
    </dependency>
    <dependency>
        <groupId>commons-lang</groupId>
        <artifactId>commons-lang</artifactId>
        <version>2.6</version>
    </dependency>

Adding the logs as requested.

[WARNING]
[WARNING] Some problems were encountered while building the effective settings
[WARNING] 'proxies.proxy.id' must be unique but found duplicate proxy with id optional @ C:\apache-maven-3.3.9\conf\settings.xml
[WARNING]
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building POC-REST 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ POC-REST ---
[INFO] Deleting c:\Workspace_Github\POC-REST\target
[INFO]
[INFO] >>> spring-boot-maven-plugin:2.0.2.RELEASE:run (default-cli) > test-compile @ POC-REST >>>
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ POC-REST ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ POC-REST ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 52 source files to c:\Workspace_Github\POC-REST\target\classes
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:testResources (default-testResources) @ POC-REST ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory c:\Workspace_Github\POC-REST\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ POC-REST ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to c:\Workspace_Github\POC-REST\target\test-classes
[INFO]
[INFO] <<< spring-boot-maven-plugin:2.0.2.RELEASE:run (default-cli) < test-compile @ POC-REST <<<
[INFO]
[INFO] --- spring-boot-maven-plugin:2.0.2.RELEASE:run (default-cli) @ POC-REST ---
2018-07-02 14:22:12.463  INFO 2892 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@1574712c: startup date [Mon Jul 02 14:22:12 EDT 2018]; root of context hierarchy
2018-07-02 14:22:12.931  INFO 2892 --- [           main] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2018-07-02 14:22:13.126  INFO 2892 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$a39c3820] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.0.2.RELEASE)

2018-07-02 14:22:18.116  INFO 2892 --- [ost-startStop-1] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3462 ms
2018-07-02 14:22:26.988  INFO 2892 --- [           main] o.s.s.web.DefaultSecurityFilterChain     : Creating filter chain: org.springframework.security.web.util.matcher.AnyRequestMatcher@1, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@377a610f, org.springframework.security.web.context.SecurityContextPersistenceFilter@31b29aea, org.springframework.security.web.header.HeaderWriterFilter@228598d, org.springframework.security.web.authentication.logout.LogoutFilter@4e4795c, com.mhf.ids_rest.jwt.CustomCorsFilter@5b5256fd, com.mhf.ids_rest.jwt.security.auth.ajax.AjaxLoginProcessingFilter@4bda7dc, com.mhf.ids_rest.jwt.security.auth.jwt.JwtTokenAuthenticationProcessingFilter@3c9d3b31, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@3a981279, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@3327dc67, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@580b47b4, org.springframework.security.web.session.SessionManagementFilter@3f1d99a8, org.springframework.security.web.access.ExceptionTranslationFilter@236d4b91, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@2259c500]
2018-07-02 14:22:27.063  WARN 2892 --- [           main] c.n.c.sources.URLConfigurationSource     : No URLs will be polled as dynamic configuration sources.
2018-07-02 14:22:27.074  WARN 2892 --- [           main] c.n.c.sources.URLConfigurationSource     : No URLs will be polled as dynamic configuration sources.
2018-07-02 14:22:27.179  INFO 2892 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**/favicon.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-07-02 14:22:27.301  INFO 2892 --- [           main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for @ControllerAdvice: org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@696771bc: startup date [Mon Jul 02 14:22:14 EDT 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@1574712c
2018-07-02 14:22:27.366  WARN 2892 --- [           main] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2018-07-02 14:22:27.414  INFO 2892 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/]}" onto public org.springframework.http.ResponseEntity<?> com.mhf.ids_rest.controller.PingController.home()
2018-07-02 14:22:27.418  INFO 2892 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/sample-data/function2/data1/{data1}/data2/{data2}/data3/{data3}],methods=[GET],produces=[application/json]}" onto public org.springframework.http.ResponseEntity<?> com.mhf.ids_rest.controller.RestApiController.getFunction1(int,int,java.lang.String)
2018-07-02 14:22:27.419  INFO 2892 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/sample-data/function1/data1/{data1}],methods=[GET],produces=[application/json]}" onto public org.springframework.http.ResponseEntity<?> com.mhf.ids_rest.controller.RestApiController.getFunction2(java.lang.String)
2018-07-02 14:22:27.420  INFO 2892 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/api/me],methods=[GET]}" onto public com.mhf.ids_rest.jwt.security.model.UserContext com.mhf.ids_rest.jwt.profile.endpoint.ProfileEndpoint.get(com.mhf.ids_rest.jwt.security.auth.JwtAuthenticationToken)
2018-07-02 14:22:27.421  INFO 2892 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/api/auth/token],methods=[GET],produces=[application/json]}" onto public com.mhf.ids_rest.jwt.security.model.token.JwtToken com.mhf.ids_rest.jwt.security.endpoint.RefreshTokenEndpoint.refreshToken(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) throws java.io.IOException,javax.servlet.ServletException
2018-07-02 14:22:27.426  INFO 2892 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2018-07-02 14:22:27.427  INFO 2892 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.servlet.error.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-07-02 14:22:27.465  INFO 2892 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-07-02 14:22:27.465  INFO 2892 --- [           main] o.s.w.s.handler.SimpleUrlHandlerMapping  : Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]

Main class :

@EnableEurekaClient
@SpringBootApplication(scanBasePackages= {"com.blah.poc_rest"})
@EnableConfigurationProperties
@EnableCaching
public class POCRESTApp 
{
    public static void main( String[] args )
    {
        SpringApplication.run(POCRESTApp.class, args);
    }
}

This is my app. Am putting all three classes in the same block for convenience.

@RestController
@RequestMapping("/sample-data")
public class POCApiController { 

    @Autowired
    SampleService sampleService;    


    @RequestMapping(value="/function1/param1/{param1}", 
            method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<?> getData(@PathVariable("param1") String param1){        
        System.out.println("Controller called...");     
        String results = sampleService.getData(param1);
        return new ResponseEntity<String>(results, HttpStatus.OK);      
    }

}


public interface SampleService {    
    public String getData(final String param);
}


@Service
@CacheConfig(cacheNames = "sampleCachedData")
public class SampleServiceImpl implements SampleService {

    @Override
    @Cacheable
    public String getData(String param) {
        System.out.println("Service called... ");
        return "greetings"+param;
    }

}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Augie
  • 33
  • 6
  • can you please share some logs or your sample application so we can investigate further. A question: How do you want Hazelcast members to discover each other? Because from above config, members will use Multicast to discover each other. – Gokhan Oner Jul 02 '18 at 17:40
  • Thanks for your response. I have updated the logs in the question.I intend to use multicast. But before that, we should see some activity of hazelcast getting started right ? I dont see even that. – Augie Jul 02 '18 at 18:28
  • I tried the same, after adding `Config` bean, I can see that Hazelcast instance starts. Can you please make sure `CacheConfig` is under the same package hierarchy with your Main class. Also, to understand the issue better, can you add a `HazelcastInstance` bean instead of `Config` bean. We then need to see an Instance is started. If not, then your config class is not auto-detected. – Gokhan Oner Jul 02 '18 at 19:05
  • Tried the HazelcastInstance bean. Nothing changed. Yes, the config and the main class are on the same package (com.blah.poc_rest) . I have updated the post on how the Main class looks like. – Augie Jul 02 '18 at 20:07
  • Then it means Spring is not creating `HazelcastInstance` bean at all. Can you confirm that by putting some logs to that Bean definition? – Gokhan Oner Jul 02 '18 at 20:33
  • The instantiation is happening I believe. I did some sysouts in the HazelcastInstance Bean and I see this "HazelcastInstance{name='_hzInstance_1_dev', node=[10.183.32.133]:5702}" . Other than this, I dont see any other activity. – Augie Jul 02 '18 at 21:05
  • OK, this shows that instance is running. What do you want to see more, HZ logs in the application log file? – Gokhan Oner Jul 03 '18 at 05:50
  • Yes. When I setup a blank project with rest api, I am able to see them and the nodes available currently. When I start another instance, I see the logs updated and two nodes. In this project why dont I see any of that. I want to make sure that spring security or JWT or any other modules are not affecting this. – Augie Jul 06 '18 at 21:58
  • Ok, I added caching to some service methods and tried to see if the caching works. And It did. The first time, it was a miss and the second request was a hit. Now, I started a second instance and tried the same. The cache works on individual instances but they are not visible to each other. So, data cached on one instance is not available to the other. – Augie Jul 09 '18 at 19:14
  • Is it possible to share a sample app so I can check? – Gokhan Oner Jul 09 '18 at 20:55
  • You were right, I mistakenly added log levels to WARN (I have no idea I did this) and hence no logs were available. Sorry about that. I have added the sample app to the description. – Augie Jul 09 '18 at 22:13

0 Answers0