close

Filter

Elastic Social Manual / Version 2406.0

Table Of Contents

4.7.1 Apache Maven

CoreMedia provides BOM POMs for simple dependency management with Apache Maven. To use Elastic Social artifacts, your POM needs to import the BOM POMs. The BOM POMs ensure that you use artifacts of compatible versions and also manage the scope of all Elastic Social dependencies. API modules have compile scope, test utility modules have test scope and all other modules have runtime scope.

When using Elastic Social, you need to define dependencies to the API modules and to the implementation modules you are going to use. A typical usage of Elastic Social dependencies is shown below. Besides the API dependencies, the Elastic Core implementations for MongoDB, Apache Solr and Spring Security are included as well as the Elastic Social implementation module. For testing a dependency to the Elastic Core test utility module is declared.

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
                             http://maven.apache.org/xsd/maven-4.0.0.xsd">
  ...
  <dependencies>
    ...
    <!-- allowed Elastic Core and Elastic Social dependencies:
         core-api, social-api: compile
         others: runtime
     -->
    <dependency>
      <groupId>com.coremedia.elastic.core</groupId>
      <artifactId>core-api</artifactId>
    </dependency>
    <dependency>
      <groupId>com.coremedia.elastic.social</groupId>
      <artifactId>social-api</artifactId>
    </dependency>
    <dependency>
      <groupId>com.coremedia.elastic.core</groupId>
      <artifactId>core-solr</artifactId>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>com.coremedia.elastic.core</groupId>
      <artifactId>core-mongodb</artifactId>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>com.coremedia.elastic.social</groupId>
      <artifactId>social-spring-security</artifactId>
      <scope>runtime</scope>
    </dependency>
    <dependency>
      <groupId>com.coremedia.elastic.social</groupId>
      <artifactId>social-impl</artifactId>
      <scope>runtime</scope>
    </dependency>
    ...
  </dependencies>
  ...
</project>

         

Example 4.13. Typical Elastic Social dependencies


Application context setup

To configure Elastic Social you need to enable Spring classpath scanning for the package com.coremedia.elastic. Configuration properties will be accessed through the Spring framework Environment which collects all property sources. Two additional beans need to be configured. A bean of type org.springframework.mail.javamail.JavaMailSender needs to be defined for the MailService and an implementation of a MailTemplateService needs to be provided. An example for a Spring configuration is shown below. If you use the InMemoryMailTemplateService, you need to have a dependency on the Elastic Social social-base module.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:context="http://www.springframework.org/schema/context"
 xmlns:util="http://www.springframework.org/schema/util"
 xsi:schemaLocation="http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/context
  http://www.springframework.org/schema/context/spring- \
    context.xsd
  http://www.springframework.org/schema/util
  http://www.springframework.org/schema/util/spring-util.xsd">

 <context:component-scan base-package="com.coremedia.elastic"/>

 <bean class="org.springframework.mail.javamail. \
       JavaMailSenderImpl">
   <property name="host" value="mail.example.com"/>
   <property name="port" value="25"/>
 </bean>

 <bean class="com.coremedia.elastic.social. \
       base.mail.InMemoryMailTemplateService">
   <property name="mailTemplates">
     <set>
       <bean class="com.coremedia.elastic.social. \
             base.mail.InMemoryMailTemplate">
         <property name="name">
           <util:constant static-field="com.coremedia.elastic. \
               social.api.MailTemplates.COMMENT_REJECTED"/>
         </property>
         <property name="locale" value="ROOT"/>
         <property name="from" value="reject-contribution@example.com"/>
         <property name="subject" value="Rejected contribution \
               at example.com"/>
         <property name="text">
           <value><![CDATA[Hello ${name},

your comment below from ${commentDate} has not been published:

"${commentText}"

Please comply to our community policy when writing contributions.

Kind regards,
the editors
]]></value>
         </property>
       </bean>
     </set>
   </property>
 </bean>
</beans>
          

Example 4.14. Application context Spring example configuration


If you have a CoreMedia CAE application, just name the property file /WEB-INF/component-elastic.properties and its properties will be automatically be loaded without the need to configure a PropertyPlaceholderConfigurer.

Note that default values cannot be configured using a standard Spring PropertiesSourcesPlaceholderConfigurer as shown in Example 4.15, “Invalid configuration setup”.

<context:property-placeholder location="classpath:/com/acme/es-defaults.properties"/>

Example 4.15. Invalid configuration setup


You must use a custom configuration class and Spring annotations org.springframework.context.annotation.Configuration and org.springframework.context.annotation.PropertySource instead, as shown in Example 4.16, “Default configuration setup example”.

@Configuration(proxyBeanMethods = false)
@PropertySource(name = "es-defaults", value = {"classpath:/com/acme/es-defaults.properties"})
public class MyElasticSocialConfiguration {
  ...
}

Example 4.16. Default configuration setup example


An example of a /com/acme/es-defaults.properties file used by the Spring configuration above is shown below:

mongodb.prefix=example-project-prefix
mongodb.client-uri=mongodb://mongo1.example.com:27017, \
    mongo2.example.com:27017,mongo3.example.com:27017

mongodb.models.create-indexes=true
taskqueues.worker-node=true

elastic.solr.indexPrefix=example-project-prefix
elastic.solr.url=http://solr.example.com:40080/solr

          

Example 4.17. Example of the /com/acme/es-defaults.properties file


Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.