AnsweredAssumed Answered

Webscript, Sping, iBatis e Context Initialization Failed

Question asked by exel88 on Feb 25, 2011
Latest reply on Feb 25, 2011 by exel88
Buongiorno a tutti,
sono nuovo in questo forum e direi che sono nuovo anche nello sviluppo per Alfresco. :)

In questi giorni ho cercato di risolvere vari problemi riguardanti lo sviluppo di un webscript in Java per Alfresco che non riesco, dopo numerosi tentativi, correzione, eccetera, a deployare completamente nel server.
Ho commentato varie porzioni del codice fino a raggiungere un punto in cui posso dire con quasi certezza di aver individuato cosa non funziona, ma non riesco comunque a sistemarlo.

Vi incollo codice, eccezione, e struttura delle directory di seguito.
Uso Alfresco Community Edition 3.4 installata su server Tomcat (ho utilizzato comunque l'installazione completa di Alfresco dall'eseguibile).


10:49:07,159  INFO  [alfresco.config.FixedPropertyPlaceholderConfigurer] Loading properties file from URL [file:/C:/Users/andrea/Lavoro/Alfresco/tomcat/shared/classes/alfresco/extension/custom-vti.properties]
10:49:07,194  ERROR [web.context.ContextLoader] Context initialization failed
org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/classpath*:/db.properties]
    at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:78)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:624)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:599)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:398)
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:261)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:192)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
    at org.alfresco.web.app.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:63)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3972)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4467)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:637)
    at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:563)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:498)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:519)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/classpath*:/db.properties]
    at org.springframework.web.context.support.ServletContextResource.getInputStream(ServletContextResource.java:118)
    at org.springframework.core.io.support.PropertiesLoaderSupport.loadProperties(PropertiesLoaderSupport.java:181)
    at org.springframework.core.io.support.PropertiesLoaderSupport.mergeProperties(PropertiesLoaderSupport.java:161)
    at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:69)
    … 31 more
log4j:ERROR LogMananger.repositorySelector was null likely due to error in class reloading, using NOPLoggerRepository.
10:49:33,492  INFO  [extensions.webscripts.DeclarativeRegistry] Registered 309 Web Scripts (+0 failed), 319 URLs


La struttura delle directory nel JAR (che copio in WEB-INF/lib per eseguire il deploy) è la seguente:

. alfresco/
     . extension/
           . module-context-xml
           . module.properties
           . nomeDelWS.post.desc.xml
           . nomeDelWS.post.html.ftl
. it/
   . a/
       . b/
           . nomeDelWS/
                  . dao (contiene .class)
                          . maps (contiene gli xml di ibatis)
                  . domain (contiene .class)
                  . support (contiene .class)
                  . util (contiene .class)
                  . webscript
                        . ProtocolloFileUpload.class
. META-INF
. db.properties
. log4j.properties
. sql-map-config.xml



Questo è il MANIFEST-MF:
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.1
Created-By: 17.1-b03 (Sun Microsystems Inc.)

… e infine questo è il file incriminato  :D (ho messo degli * per evidenziarvi una porzioncina del codice, che se commentata sembra non dare problemi) : module-context.xml

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
   <bean id="webscript.it.a.b.nomeDelWS.webscript.ProtocolloFileUpload.post" class="it.a.b.nomeDelWS.webscript.ProtocolloFileUpload"
      parent="webscript">

      <property name="authenticationService" ref="authenticationService" />
      <property name="nodeService" ref="nodeService" />
      <property name="namespaceService" ref="namespaceService" />
      <property name="fileFolderService" ref="fileFolderService" />
      <property name="contentService" ref="contentService" />
      <property name="searchService" ref="searchService" />
      <property name="authorityService" ref="authorityService" />
      <property name="transactionService" ref="transactionService" />
      <property name="permissionService" ref="permissionService" />
      <property name="categoryService" ref="categoryService" />
   </bean>

*   <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
*            <property name="location">
*         <value>classpath*:/db.properties</value>
*      </property>
*   </bean>
   
   <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
      <property name="driverClassName" value="${jdbc.driverClassName}" />
      <property name="url" value="${jdbc.url}" />
      <property name="username" value="${jdbc.username}" />
      <property name="password" value="${jdbc.password}" />
   </bean>

   <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
      <property name="dataSource" ref="dataSource" />
   </bean>

   <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
      <property name="configLocation" value="classpath:/sql-map-config.xml" />
      <property name="dataSource" ref="dataSource" />
   </bean>

   <bean id="daoSupport" class="it.insiel.archprot.protocolloAlfrescoInsiel.dao.DAOUtils">
      <property name="sqlMapClient" ref="sqlMapClient" />
   </bean>

   <bean id="interactionsDAO" class="it.insiel.archprot.protocolloAlfrescoInsiel.dao.InteractionsDAO">
      <property name="support" ref="daoSupport" />
   </bean>
   
</beans>

Ho provato a sostituire la porzione:
   
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
      <property name="location">
         <value>classpath*:/db.properties</value>
      </property>
</bean>
con:

   <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
      <property name="location">
         <value>classpath:/db.properties</value>
      </property>
   </bean>

In questo caso l'eccezione è la seguente:

11:13:21,599  INFO  [alfresco.config.FixedPropertyPlaceholderConfigurer] Loading properties file from class path resource [alfresco/domain/cache-strategies.properties]
11:13:21,683  INFO  [alfresco.config.FixedPropertyPlaceholderConfigurer] Loading properties file from class path resource [alfresco/module/org.alfresco.module.vti/context/vti.properties]
11:13:21,686  INFO  [alfresco.config.FixedPropertyPlaceholderConfigurer] Loading properties file from URL [file:/C:/Users/andrea/Lavoro/Alfresco/tomcat/shared/classes/alfresco/extension/custom-vti.properties]
11:13:21,804  ERROR [web.context.ContextLoader] Context initialization failed
org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'clusterPropertySetter' defined in class path resource [alfresco/core-services-context.xml]: Could not resolve placeholder 'alfresco.tcp.start_port'
    at org.springframework.beans.factory.config.PropertyPlaceholderConfigurer.processProperties(PropertyPlaceholderConfigurer.java:272)
    at org.springframework.beans.factory.config.PropertyResourceConfigurer.postProcessBeanFactory(PropertyResourceConfigurer.java:75)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:624)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:599)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:398)
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:261)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:192)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
    at org.alfresco.web.app.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:63)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3972)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:4467)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:637)
    at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:563)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:498)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
    at org.apache.catalina.core.StandardService.start(StandardService.java:519)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
log4j:ERROR LogMananger.repositorySelector was null likely due to error in class reloading, using NOPLoggerRepository..

Tutte e tre le "versioni" hanno dato lo stesso risultato.

La cartella A e la cartella B ovviamente hanno altri nomi, ma ho mantenuto la struttura così come la utilizzo io. Anche "nomeDelWS" ovviamente è un altro, ma per motivi lavorativi preferisco non scriverlo qui. :)

Grazie,


Andrea

Outcomes