Adding configuration-based (rather than programmatic config) Hazelcast to Springboot?

194 views
Skip to first unread message

o haya

unread,
Mar 31, 2022, 9:57:04 AM3/31/22
to Hazelcast
Hi,

I am working on a new Springboot app (porting an existing app to Springboot).  One of my colleagues had created and tested the base Springboot app, with healtcheck and I am starting with taht.

The original app used Hazelcast caching (non-clustered, just caching), and uses configuration-based configuration for Hazelcast (i.e., using hazelcast.xml, vs. programmatic configuration).  

I originally was told that I just needed to add the "@EnableCaching" annotation to the main Springboot app, but when I do that and try to build, I am getting:

 cannot find symbol
  symbol: class EnableCaching

I have already added the 2 dependencies in the pom.xml:

        <dependency>
            <groupId>com.hazelcast</groupId>
            <artifactId>hazelcast</artifactId>
            <version>4.2.2</version>
        </dependency>
        <dependency>
            <groupId>com.hazelcast</groupId>
            <artifactId>hazelcast-spring</artifactId>
            <version>4.2.2</version>
            <scope>compile</scope>
        </dependency>        

Can someone tell me why I am getting that "cannot find symbol"?  What else do I need to do to get Hazelcast integrated with the new app?

Thanks,
Jim

o haya

unread,
Mar 31, 2022, 10:14:49 AM3/31/22
to Hazelcast

Hi,

I found the problem with that cannot find symbol... stupid on my part, really :(!!!  I hadn't realized that after I added the @EnableCaching annotation, I *ALSO* had to add an import for "org.springframework.cache.annotation.EnableCaching"!!

After that, the project builds ok in Eclipse!

Jim

o haya

unread,
Mar 31, 2022, 3:34:35 PM3/31/22
to Hazelcast
Hi,

When I start the application (after adding the @EnableCaching annotation and the hazelcast dependies mentioned earlier), the app does start, but I was wondering:  Should I get any indication that Hazelcast is actuall working at the startup?  Right now in the Eclipse console logging there doesn't seem to be any indication about hazelcast.

2022-03-31 15:28:32.945  INFO 60968 --- [  restartedMain] m.n.g.o.OrchestratorApplication          : Starting
2022-03-31 15:28:32.958  INFO 60968 --- [  restartedMain] m.n.g.o.OrchestratorApplication          : No active profile set, falling back to default profiles: default
2022-03-31 15:28:33.135  INFO 60968 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable
2022-03-31 15:28:33.135  INFO 60968 --- [  restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'
2022-03-31 15:28:35.023  INFO 60968 --- [  restartedMain] o.s.b.w.e.t.TomcatWebServer              : Tomcat initialized with port(s): 18443 (http)
2022-03-31 15:28:35.058  INFO 60968 --- [  restartedMain] o.a.c.c.StandardService                  : Starting service [Tomcat]
2022-03-31 15:28:35.058  INFO 60968 --- [  restartedMain] o.a.c.c.StandardEngine                   : Starting Servlet engine: [Apache Tomcat/9.0.56]
2022-03-31 15:28:35.365  INFO 60968 --- [  restartedMain] o.a.c.c.C.[.[.[/v1]                      : Initializing Spring embedded WebApplicationContext
2022-03-31 15:28:35.365  INFO 60968 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2229 ms
2022-03-31 15:28:37.471  WARN 60968 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : Unable to start LiveReload server
2022-03-31 15:28:37.559  INFO 60968 --- [  restartedMain] o.s.b.w.e.t.TomcatWebServer              : Tomcat started on port(s): 18443 (http) with context path '/v1'
2022-03-31 15:28:37.582  INFO 60968 --- [  restartedMain] m.n.g.o.OrchestratorApplication          : Started OrchestratorApplication in 5.317 seconds (JVM running for 6.923)

Thanks,
Jim

o haya

unread,
Mar 31, 2022, 4:43:13 PM3/31/22
to Hazelcast
Hi,

I put a copy of the hazelcast.xml from the original rest web app into the springboot resource directory and when I tried to start the Springboot app, I ght the console output as above, but additionally:

022-03-31 15:46:51.503  INFO 129580 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2213 ms
2022-03-31 15:46:53.099  INFO 129580 --- [  restartedMain] c.h.i.c.AbstractConfigLocator            : Loading 'hazelcast.xml' from the classpath.
2022-03-31 15:46:53.214  WARN 129580 --- [  restartedMain] c.h.c.AbstractXmlConfigHelper            : Name of the hazelcast schema location[hazelcast-config-3.8.xsd] is incorrect, using default
2022-03-31 15:46:53.449  WARN 129580 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hazelcastInstance' defined in class path resource [org/springframework/boot/autoconfigure/hazelcast/HazelcastServerConfiguration$HazelcastServerConfigFileConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.hazelcast.core.HazelcastInstance]: Factory method 'hazelcastInstance' threw exception; nested exception is com.hazelcast.config.InvalidConfigurationException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'group'. One of '{"http://www.hazelcast.com/schema/config":import, "http://www.hazelcast.com/schema/config":config-replacers, "http://www.hazelcast.com/schema/config":cluster-name, "http://www.hazelcast.com/schema/config":license-key, "http://www.hazelcast.com/schema/config":instance-name, "http://www.hazelcast.com/schema/config":management-center, "http://www.hazelcast.com/schema/config":properties, "http://www.hazelcast.com/schema/config":wan-replication, "http://www.hazelcast.com/schema/config":network, "http://www.hazelcast.com/schema/config":partition-group, "http://www.hazelcast.com/schema/config":executor-service, "http://www.hazelcast.com/schema/config":durable-executor-service, "http://www.hazelcast.com/schema/config":scheduled-executor-service, "http://www.hazelcast.com/schema/config":queue, "http://www.hazelcast.com/schema/config":map, "http://www.hazelcast.com/schema/config":multimap, "http://www.hazelcast.com/schema/config":replicatedmap, "http://www.hazelcast.com/schema/config":cache, "http://www.hazelcast.com/schema/config":list, "http://www.hazelcast.com/schema/config":set, "http://www.hazelcast.com/schema/config":topic, "http://www.hazelcast.com/schema/config":reliable-topic, "http://www.hazelcast.com/schema/config":ringbuffer, "http://www.hazelcast.com/schema/config":listeners, "http://www.hazelcast.com/schema/config":serialization, "http://www.hazelcast.com/schema/config":native-memory, "http://www.hazelcast.com/schema/config":security, "http://www.hazelcast.com/schema/config":member-attributes, "http://www.hazelcast.com/schema/config":split-brain-protection, "http://www.hazelcast.com/schema/config":lite-member, "http://www.hazelcast.com/schema/config":hot-restart-persistence, "http://www.hazelcast.com/schema/config":user-code-deployment, "http://www.hazelcast.com/schema/config":cardinality-estimator, "http://www.hazelcast.com/schema/config":flake-id-generator, "http://www.hazelcast.com/schema/config":crdt-replication, "http://www.hazelcast.com/schema/config":pn-counter, "http://www.hazelcast.com/schema/config":advanced-network, "http://www.hazelcast.com/schema/config":cp-subsystem, "http://www.hazelcast.com/schema/config":auditlog, "http://www.hazelcast.com/schema/config":metrics, "http://www.hazelcast.com/schema/config":instance-tracking, "http://www.hazelcast.com/schema/config":sql}' is expected.
2022-03-31 15:46:53.455  INFO 129580 --- [  restartedMain] o.a.c.c.StandardService                  : Stopping service [Tomcat]
2022-03-31 15:46:53.479  INFO 129580 --- [  restartedMain] ConditionEvaluationReportLoggingListener : 

The hazelcast.xml is as follows:

<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright (c) 2008-2017, Hazelcast, Inc. All Rights Reserved.
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~ http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->

<!--
    Please see the schema for how to configure Hazelcast at https://hazelcast.com/schema/config/hazelcast-config-3.8.xsd
    or the documentation at https://hazelcast.org/documentation/
-->
<hazelcast xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.8.xsd"
           xmlns="http://www.hazelcast.com/schema/config"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <group>
        <name>dev</name>
        <password>dev-pass</password>
    </group>
    <properties>
        <property name="hazelcast.logging.type">log4j</property>
    </properties>
    <management-center enabled="false">http://localhost:8080/mancenter</management-center>
    <network>
        <port auto-increment="true" port-count="100">5701</port>
        <outbound-ports>
            <ports>0</ports>
        </outbound-ports>
        <join>
            <multicast enabled="false">
                <multicast-group>224.2.2.3</multicast-group>
                <multicast-port>54327</multicast-port>
            </multicast>
            <discovery-strategies>
            </discovery-strategies>
        </join>
    </network>
   
    <map name="orchestratorMap">
        <in-memory-format>BINARY</in-memory-format>
        <backup-count>1</backup-count>
        <async-backup-count>0</async-backup-count>
        <time-to-live-seconds>3600</time-to-live-seconds>
        <max-idle-seconds>0</max-idle-seconds>
        <eviction-policy>LRU</eviction-policy>
        <max-size policy="PER_NODE">10000</max-size>
    </map>
    <services enable-defaults="true"/>
</hazelcast> 

What might be causing the problem?

Thanks,
Jim

o haya

unread,
Mar 31, 2022, 4:57:39 PM3/31/22
to Hazelcast
Hi,

I found a really simple hazelcast.xml:

<hazelcast
   xsi:schemaLocation="http://www.hazelcast.com/schema/config  
   <!-- name of the instance -->
   <instance-name>XML_Hazelcast_Instance</instance-name>

and when I use this hazelcast.xml, the Springboot app is starting up ok and the console log has:

2022-03-31 16:53:41.487  INFO 32616 --- [  restartedMain] c.h.i.c.AbstractConfigLocator            : Loading 'hazelcast.xml' from the classpath.
2022-03-31 16:53:41.552  WARN 32616 --- [  restartedMain] c.h.c.AbstractXmlConfigHelper            : Name of the hazelcast schema location[http://www.hazelcast.com/schema/config/hazelcast-config-3.12.12.xsd] is incorrect, using default
2022-03-31 16:53:41.874  INFO 32616 --- [  restartedMain] c.h.system                               : [10.0.10.10]:5701 [dev] [4.2.2] Hazelcast 4.2.2 (20210811 - c38011e) starting at [10.0.10.10]:5701
2022-03-31 16:53:42.390  INFO 32616 --- [  restartedMain] c.h.s.d.i.DiscoveryService               : [10.0.10.10]:5701 [dev] [4.2.2] No discovery strategy is applicable for auto-detection
2022-03-31 16:53:42.560  INFO 32616 --- [  restartedMain] c.h.i.i.Node                             : [10.0.10.10]:5701 [dev] [4.2.2] Using Multicast discovery
2022-03-31 16:53:42.565  WARN 32616 --- [  restartedMain] c.h.c.CPSubsystem                        : [10.0.10.10]:5701 [dev] [4.2.2] CP Subsystem is not enabled. CP data structures will operate in UNSAFE mode! Please note that UNSAFE mode will not provide strong consistency guarantees.
2022-03-31 16:53:42.907  INFO 32616 --- [  restartedMain] c.h.i.d.Diagnostics                      : [10.0.10.10]:5701 [dev] [4.2.2] Diagnostics disabled. To enable add -Dhazelcast.diagnostics.enabled=true to the JVM arguments.
2022-03-31 16:53:42.916  INFO 32616 --- [  restartedMain] c.h.c.LifecycleService                   : [10.0.10.10]:5701 [dev] [4.2.2] [10.0.10.10]:5701 is STARTING
2022-03-31 16:53:44.931  INFO 32616 --- [  restartedMain] c.h.i.c.ClusterService                   : [10.0.10.10]:5701 [dev] [4.2.2]

Members {size:1, ver:1} [
    Member [10.0.10.10]:5701 - bdd931c2-c0d6-4160-adeb-73c389b3e882 this
]

2022-03-31 16:53:44.950  INFO 32616 --- [  restartedMain] c.h.c.LifecycleService                   : [10.0.10.10]:5701 [dev] [4.2.2] [10.0.10.10]:5701 is STARTED
2022-03-31 16:53:45.110  INFO 32616 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2022-03-31 16:53:45.153  INFO 32616 --- [  restartedMain] o.s.b.w.e.t.TomcatWebServer              : Tomcat started on port(s): 18443 (http) with context path '/v1'
2022-03-31 16:53:45.168  INFO 32616 --- [  restartedMain] m.n.g.o.OrchestratorApplication          : Started OrchestratorApplication in 7.253 seconds (JVM running for 8.482)

So it seems like the 1st hazelcast.xml (the one from the original rest app) is just not good for the version of Hazelcast I am using (4.2.2)?

Thanks,
Jim

Josef Cacek

unread,
Apr 1, 2022, 2:35:57 AM4/1/22
to haze...@googlegroups.com
Hi Jim,
one of the breaking changes between Hazelcast 3.y and 4.y is replacing
the <group> element with simple <cluster-name> in the configuration.

Compare:
* https://github.com/hazelcast/hazelcast/blob/v4.2.2/hazelcast/src/main/resources/hazelcast-default.xml#L34
* https://github.com/hazelcast/hazelcast/blob/v3.8/hazelcast/src/main/resources/hazelcast-default.xml#L26-L29

I suggest looking into hazelcast-full-example.xml file for your
Hazelcast version. There you can find available configuration options
with descriptions.
E.g. https://github.com/hazelcast/hazelcast/blob/v4.2.2/hazelcast/src/main/resources/hazelcast-full-example.xml

Regards,
-- Josef
> --
> You received this message because you are subscribed to the Google Groups "Hazelcast" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/hazelcast/e80597ff-ae55-4ad1-997d-93e6540840b0n%40googlegroups.com.

--
This message contains confidential information and is intended only for the
individuals named. If you are not the named addressee you should not
disseminate, distribute or copy this e-mail. Please notify the sender
immediately by e-mail if you have received this e-mail by mistake and
delete this e-mail from your system. E-mail transmission cannot be
guaranteed to be secure or error-free as information could be intercepted,
corrupted, lost, destroyed, arrive late or incomplete, or contain viruses.
The sender therefore does not accept liability for any errors or omissions
in the contents of this message, which arise as a result of e-mail
transmission. If verification is required, please request a hard-copy
version. -Hazelcast
Reply all
Reply to author
Forward
0 new messages