initialization problem of the application context of the API alfresco repository version 6.X or 7.X

cancel
Showing results for 
Search instead for 
Did you mean: 
compiii
Member II

initialization problem of the application context of the API alfresco repository version 6.X or 7.X

Hi to all!

When I want to initialize the #application context of the API #alfresco repository version 6.X or 7.X (I have tested the lastest version 7.78 and the version 6.57), I have these errors:

Configuration problem: Failed to import bean definitions from URL location [classpath:alfresco/application-context-core.xml]

Offending resource: class path resource [alfresco/application-context.xml]; nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:alfresco/core-services-context.xml]

Offending resource: class path resource [alfresco/application-context-core.xml]; nested exception is org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 587 in XML document from class path resource [alfresco/core-services-context.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 587; columnNumber: 107; cvc-datatype-valid.1.2.1: 'cm:constraintRegistry' is not a valid value for 'NCName'.

My code is very simple:

public class AlfrescoApp {

    public static void main(String[] args) {

        try {
            ServiceRegistry serviceRegistry = null;
            ApplicationContext context = null;
            context = new ClassPathXmlApplicationContext("alfresco/application-context.xml");
                
            serviceRegistry = (ServiceRegistry) context.getBean(ServiceRegistry.SERVICE_REGISTRY);
            AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
            
            NodeService nodeService = serviceRegistry.getNodeService();
           
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
    }

 and this is the content of my POM.xml file:

<?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">
<modelVersion>4.0.0</modelVersion>

  <groupId>com.alfresco.project</groupId>
  <artifactId>white_box_project_alfresco</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>

  <dependencies>
        <dependency>
               <groupId>org.alfresco</groupId>
              <artifactId>alfresco-repository</artifactId>
              <version>7.78</version>
        </dependency>
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
                <version>5.1.32</version>
            </dependency>          
       
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-beans</artifactId>
                <version>4.1.0.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
                <version>4.1.0.RELEASE</version>
            </dependency>
       
             <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <version>4.1.0.RELEASE</version>
            </dependency>
           <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aspects</artifactId>
                <version>4.1.0.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-tx</artifactId>
                <version>4.1.0.RELEASE</version>
            </dependency>
           <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-expression</artifactId>
                <version>4.1.0.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-orm</artifactId>
                <version>3.2.14.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-jdbc</artifactId>
                <version>4.1.0.RELEASE</version>
            </dependency>
            
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring</artifactId>
                <version>2.5</version>
            </dependency>
  </dependencies>

    <build>

        <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>Cp1252</encoding>
                </configuration>
            </plugin>
        </plugins>

    </build>

<repositories>
        <repository>
            <id>alfresco-public</id>
            <url>https://artifacts.alfresco.com/nexus/content/repositories/public/</url>
        </repository>
    <repository>
      <id>jboss-public-repository-group</id>
      <name>JBoss Public Repository Group</name>
      <url>http://repository.jboss.org/nexus/content/groups/public/</url>
      <releases>
        <updatePolicy>never</updatePolicy>
      </releases>
      <snapshots>
        <updatePolicy>daily</updatePolicy>
      </snapshots>
    </repository>
  </repositories>

</project>

I don't know why I have these errors with this above code. Please could you help me to solve this problem?

2 Replies
afaust
Master

Re: initialization problem of the application context of the API alfresco repository version 6.X or 7.X

a) This kind of use of Alfresco is highly non-standard. Alfresco has not been designed to be used as an embeddable component. It can be used that way, but requires extensive understanding of the platform / product to get right.

b) You are using different versions of libraries than what Alfresco uses (e.g. Alfresco uses Spring 5 nowadays)

c) cp1252, really? It is 2019 - use UTF-8 and kill all the legacy encodings

In short: Don't try to integrate Alfresco by embedding it into some project. Integrate by usings its ReST APIs. Or - if you want to develop an extension - use the Alfresco SDK to create a project structure to do that in the proper way.

janv
Alfresco Employee

Re: initialization problem of the application context of the API alfresco repository version 6.X or 7.X

EDIT: Looks as if Axel and I replied around the same time :-)

Please carefully check your pom dependencies.

If you're trying to compile &/or test run using latest alfresco-repository-7.78, you should use other matching dependencies (alfresco-data-model, alfresco-core, spring framework, etc) ...

https://github.com/Alfresco/alfresco-repository/blob/alfresco-repository-7.78/pom.xml

... as an example, you should use Spring Framework 5.1.8 (not 4.1.0). Similarly for all other required dependencies.

Regards,

Jan

ps. you might find it easier to start with the Alfresco (Maven) SDK before trimming down, if needed ?