Tutorials The Weather App

The Weather App

Up to now we have been configuring Infinispan through it's programmatic API, but it is also typical for applications to separate code from configuration. For this purpose we can use the declarative configuration, whereby all aspects of Infinispan can be configured using an external XML file. First of all let's convert the configuration into XML format:

        
          = preserve do
            :escaped
              
              
                    
                    
                        
                        
                        
                          
                          
                            
                          
                        
                    
              
          
        
By placing this file in Maven's src/main/resources folder, it will be available in the classpath, so that we can use it to configure the DefaultCacheManager as follows:
        
          = preserve do
            :escaped
              cacheManager = new DefaultCacheManager(WeatherApp.class.getResourceAsStream("/weatherapp-infinispan.xml"));                
        
      
You are now ready to run the code:
        
          = preserve do
            :escaped
              $ git checkout -f step-11
              $ mvn clean package exec:exec # from terminal 1
              $ mvn exec:exec # from terminal 2
        
      

Obviously, the output will be identical to the previous run, which is what we were expecting !

Conclusions

You have reached the end of this tutorial and, along the way, you have learned how to embed Infinispan in your application, not only to perform simple caching of data, but also for distributed computation and clustering. Infinispan offers many other interesting features, so please head over to our extensive documentation to learn about them.