Women in Technology

Hear us Roar



Article:
  Wiring Your Web Application with Open Source Java
Subject:   Problems
Date:   2004-06-11 13:49:10
From:   meagle
Response to: Problems

You will need to use the AOPAlliance jar file. http://sourceforge.net/projects/aopalliance


Place this file into your web-inf/lib directory. You can also download Spring 1.0.2 with dependencies if you want to get the jar from that source as well.

Full Threads Newest First

Showing messages 1 through 2 of 2.

  • Problems
    2004-06-26 20:25:48  lazyboy [View]

    I had same prob. and I had aopalliance.jar in web-inf/lib but I carelessy put a duplicate copy of spring.jar in tomcat/server/lib and I got a very similiar message you had. Remove duplicate, AOK.
    • Problems
      2006-05-27 16:13:40  hbravo80 [View]

      Utilizo lo siguiente:
      - IDE: MyEclipse 4.1.1
      - Servidor: Tomcat 5.0.28
      - Framework: spring-framework-1.2.8-with-dependencies

      Mi web.xml esta configurado asi:
      ================================

      <?xml version="1.0" encoding="UTF-8"?>
      <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
      <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/spring-context-dataSource.xml,/WEB-INF/spring-context-dao.xml,/WEB-INF/spring-context-facade.xml,/WEB-INF/spring-context-web.xml</param-value>
      </context-param>

      <filter>
      <filter-name>URLFilter</filter-name>
      <filter-class>com.empresa.web.administracion.vc.struts.filtro.URLFilter</filter-class>
      </filter>

      <filter-mapping>
      <filter-name>URLFilter</filter-name>
      <url-pattern>/*</url-pattern>
      </filter-mapping>

      <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
      </listener>

      <!-- Descomentar solo cuando su servidor use el servlet 2.0 y comentar el listener -->
      <!-- servlet>
      <servlet-name>SpringContextServlet</servlet-name>
      <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
      <load-on-startup>1</load-on-startup>
      </servlet-->

      <servlet>
      <servlet-name>action</servlet-name>
      <servlet-class>com.empresa.web.administracion.vc.struts.controller.ServletController</servlet-class>
      <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml</param-value>
      </init-param>
      <init-param>
      <param-name>debug</param-name>
      <param-value>3</param-value>
      </init-param>
      <init-param>
      <param-name>detail</param-name>
      <param-value>3</param-value>
      </init-param>
      <init-param>
      <param-name>validate</param-name>
      <param-value>true</param-value>
      </init-param>
      <init-param>
      <param-name>log4j</param-name>
      <param-value>WEB-INF/log4j.properties</param-value>
      </init-param>
      <load-on-startup>1</load-on-startup>
      </servlet>

      <servlet-mapping>
      <servlet-name>action</servlet-name>
      <url-pattern>*.do</url-pattern>
      </servlet-mapping>

      <welcome-file-list>
      <welcome-file>index.jsp</welcome-file>
      </welcome-file-list>
      </web-app>

      Mi spring-context-dataSource.xml esta configurado asi:
      =================================================
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

      <!-- Archivo de configuración de datasources, servidores de correo y plantillas de email -->
      <beans>
      <!-- DATASOURCES -->
      <bean id="dataSourceGeneral" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
      <property name="driverClassName"><value>sun.jdbc.odbc.JdbcOdbcDriver</value></property>
      <property name="url"><value>jdbc:odbc:cnxSQLServer2000</value></property>
      <property name="defaultCatalog"><value>general</value></property>
      <property name="username"><value></value></property>
      <property name="password"><value></value></property>
      </bean>
      </beans>

      Mi spring-context-dao.xml esta configurado asi:
      ===============================================
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

      <!-- Archivo de configuración de daos beans, que pueden ser invocados desde un facade -->
      <beans>
      <!-- DAOS BEANS -->
      <bean id="ubigeoDao" class="com.empresa.web.administracion.modelo.spring.daoimpl.UbigeoDaoImpl">
      <property name="dataSourceGeneral"><ref bean="dataSourceGeneral" /></property>
      </bean>
      </beans>

      Mi clase storeProcedures "ListarUbigeosSP.java"
      ===============================================
      package com.empresa.web.administracion.modelo.spring.dao.sp;

      import java.sql.ResultSet;
      import java.sql.SQLException;
      import java.sql.Types;
      import java.util.HashMap;
      import java.util.List;
      import java.util.Map;

      import javax.sql.DataSource;

      import org.apache.log4j.Logger;
      import org.springframework.jdbc.core.RowMapper;
      import org.springframework.jdbc.core.SqlParameter;
      import org.springframework.jdbc.core.SqlReturnResultSet;
      import org.springframework.jdbc.object.StoredProcedure;

      import com.empresa.web.administracion.modelo.dto.UbigeoDTO;

      public class ListarUbigeosSP extends StoredProcedure {
      static Logger logger = Logger.getLogger("administracionLog");

      UbigeoDTO ubigeoDTO = null;
      List listaUbigeos = null;

      public ListarUbigeosSP(DataSource dataSource) {
      logger.debug("Inicia el constructor ListarCombosSP");

      super.setDataSource(dataSource);
      super.setSql(NombresStoredProcedures.LISTAR_UBIGEOS_SP);

      declareParameter(new SqlReturnResultSet("rsUbigeos", new RowMapper() {
      public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
      ubigeoDTO = new UbigeoDTO();
      ubigeoDTO.setCodigoUbigeo(rs.getString("COD_UBI"));
      ubigeoDTO.setCodigoDepartamento(rs.getString("COD_DEP_UBI"));
      ubigeoDTO.setCodigoProvincia(rs.getString("COD_PRO_UBI"));
      ubigeoDTO.setCodigoDistrito(rs.getString("COD_DIS_UBI"));
      ubigeoDTO.setNombreUbigeo(rs.getString("NOM_UBI"));
      return ubigeoDTO;
      }
      }));
      declareParameter(new SqlParameter("P_CODIGO_DEPARTAMENTO", Types.CHAR));
      declareParameter(new SqlParameter("P_CODIGO_PROVINCIA", Types.CHAR));
      compile();
      }

      public List executeProcedure(String codigoDepartamento, String codigoProvincia) {
      logger.debug("Inicia el método executeProcedure de ListarUbigeosSP");
      Map paramHashMap = new HashMap();
      paramHashMap.put("P_CODIGO_DEPARTAMENTO", codigoDepartamento);
      paramHashMap.put("P_CODIGO_PROVINCIA", codigoProvincia);
      listaUbigeos = (List) super.execute(paramHashMap).get("rsUbigeos");
      return listaUbigeos;
      }
      }

      Mi interface "UbigeoDao.java"
      ============================
      package com.empresa.web.administracion.modelo.spring.dao;

      import java.util.List;

      public interface UbigeoDao {
      public List listarUbigeo(String codigoDepartamento, String codigoProvincia) throws Exception;
      }

      Mi clase que implementa dicah interface "UbigeoDaoImpl"
      =================================================
      package com.empresa.web.administracion.modelo.spring.daoimpl;

      import java.util.List;

      import com.empresa.web.framework.dao.MasterDBConnections;
      import com.empresa.web.administracion.modelo.spring.dao.UbigeoDao;
      import com.empresa.web.administracion.modelo.spring.dao.sp.ListarUbigeosSP;

      public class UbigeoDaoImpl extends MasterDBConnections implements UbigeoDao {
      public List listarUbigeo(String codigoDepartamento, String codigoProvincia) throws Exception {
      ListarUbigeosSP sp = new ListarUbigeosSP(getDataSourceGeneral());
      List listaUbigeo = sp.executeProcedure(codigoDepartamento, codigoProvincia);
      return listaUbigeo;
      }
      }

      Mi ServletController que exiende ActionServlet:
      ===============================================
      package com.empresa.web.administracion.vc.struts.controller;

      import java.io.File;
      import java.io.FileOutputStream;
      import java.io.IOException;
      import java.io.PrintWriter;
      import java.util.Iterator;
      import java.util.List;

      import javax.servlet.ServletConfig;
      import javax.servlet.ServletException;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;

      import org.apache.log4j.PropertyConfigurator;
      import org.apache.struts.action.ActionServlet;
      import org.springframework.context.ApplicationContext;
      import org.springframework.web.context.support.WebApplicationContextUtils;

      import com.empresa.web.administracion.modelo.dto.UbigeoDTO;
      import com.empresa.web.administracion.modelo.spring.dao.UbigeoDao;

      public class ServletController extends ActionServlet {
      private static final long serialVersionUID = 1L;

      public ServletController() {
      super();
      }

      public void init(ServletConfig config) throws ServletException {
      super.init(config);
      try {
      inicializarLog4J(config);
      generarJavaScriptUbigeo();
      }
      catch (Exception e) {
      e.printStackTrace();
      }
      }

      public void destroy() {
      super.destroy();
      }

      public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      }

      public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      }

      private void inicializarLog4J(ServletConfig config) throws ServletException {
      String rutaLog4J = null;
      String watch = null;

      try {
      rutaLog4J = this.getServletContext().getRealPath(config.getInitParameter("log4j"));
      if (rutaLog4J == null || rutaLog4J.length() == 0 || !(new File(rutaLog4J)).isFile()) {
      System.out.println("ERROR: No se puede leer el archivo de configuración. Por favor revise el parámetro de inicialización de la ruta del archivo de configuración en el web.xml");
      throw new ServletException();
      }
      watch = config.getInitParameter("watch");
      if (watch != null && watch.equalsIgnoreCase("true")) {
      PropertyConfigurator.configureAndWatch(rutaLog4J);
      }
      else {
      PropertyConfigurator.configure(rutaLog4J);
      }
      }
      catch (Exception e) {
      e.printStackTrace();
      }
      }

      private void generarJavaScriptUbigeo() throws ServletException, IOException {
      PrintWriter pw = null;
      ApplicationContext context = null;
      UbigeoDao ubigeoDao = null;

      List listaDepartamentos = null;
      List listaProvincias = null;
      List listaDistritos = null;

      Iterator itDepartamento = null;
      Iterator itProvincia = null;
      Iterator itDistrito = null;

      UbigeoDTO departamentoDTO = null;
      UbigeoDTO provinciaDTO = null;
      UbigeoDTO distritoDTO = null;

      int contDepartamentos = 0;
      int contProvincias = 0;
      int contDistritos = 0;

      try {
      pw = new PrintWriter(new FileOutputStream(this.getServletContext().getRealPath("/") + "\\scripts\\dataUbigeo.js"));
      context = WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
      ubigeoDao = (UbigeoDao) context.getBean("ubigeoDao");

      // Se encarga del arreglo de departamentos
      listaDepartamentos = ubigeoDao.listarUbigeo(null, null);
      pw.println("var departamentos = new Array();");
      itDepartamento = listaDepartamentos.iterator();
      while (itDepartamento.hasNext()) {
      departamentoDTO = (UbigeoDTO) itDepartamento.next();
      pw.print("var departamento = new Array();");
      pw.print("departamento[0] = '" + departamentoDTO.getCodigoUbigeo() + "';");
      pw.print("departamento[1] = '" + departamentoDTO.getCodigoDepartamento() + "';");
      pw.print("departamento[2] = '00';");
      pw.print("departamento[3] = '00';");
      pw.print("departamento[4] = '" + departamentoDTO.getNombreUbigeo() + "';");
      pw.println("departamentos[" + contDepartamentos + "] = departamento;");
      }

      // Se encarga del arreglo de provincias
      itDepartamento = listaDepartamentos.iterator();
      pw.println("var provincias = new Array();");
      while (itDepartamento.hasNext()) {
      departamentoDTO = (UbigeoDTO) itDepartamento.next();
      listaProvincias = ubigeoDao.listarUbigeo(departamentoDTO.getCodigoDepartamento(), null);
      itProvincia = listaProvincias.iterator();
      while (itProvincia.hasNext()) {
      provinciaDTO = (UbigeoDTO) itProvincia.next();
      pw.print("var provincia = new Array();");
      pw.print("provincia[0] = '" + provinciaDTO.getCodigoUbigeo() + "';");
      pw.print("provincia[1] = '" + provinciaDTO.getCodigoDepartamento() + "';");
      pw.print("provincia[2] = '" + provinciaDTO.getCodigoProvincia() + "';");
      pw.print("provincia[3] = '00';");
      pw.print("provincia[4] = '" + provinciaDTO.getNombreUbigeo() + "';");
      pw.println("provincias[" + contProvincias + "] = provincia;");
      contProvincias++;
      }
      }

      // Se encarga del arreglo de distritos
      pw.println("var distritos = new Array();");
      itDepartamento = listaDepartamentos.iterator();
      while (itDepartamento.hasNext()) {
      departamentoDTO = (UbigeoDTO) itDepartamento.next();
      listaProvincias = ubigeoDao.listarUbigeo(departamentoDTO.getCodigoDepartamento(), null);
      itProvincia = listaProvincias.iterator();
      while (itProvincia.hasNext()) {
      provinciaDTO = (UbigeoDTO) itProvincia.next();
      listaDistritos = (List) ubigeoDao.listarUbigeo(departamentoDTO.getCodigoDepartamento(), provinciaDTO.getCodigoProvincia());
      itDistrito = listaDistritos.iterator();
      while (itDistrito.hasNext()) {
      distritoDTO = (UbigeoDTO) itDistrito.next();
      pw.print("var distrito = new Array();");
      pw.print("distrito[0] = '" + distritoDTO.getCodigoUbigeo() + "';");
      pw.print("distrito[1] = '" + distritoDTO.getCodigoDepartamento() + "';");
      pw.print("distrito[2] = '" + distritoDTO.getCodigoProvincia() + "';");
      pw.print("distrito[3] = '" + distritoDTO.getCodigoDistrito() + "';");
      pw.print("distrito[4] = '" + distritoDTO.getNombreUbigeo() + "';");
      pw.println("distritos[" + contDistritos + "] = distrito;");
      contDistritos++;
      }
      }
      }

      pw.close();
      pw.flush();
      }
      catch (Exception e) {
      e.printStackTrace();
      }
      }
      }

      Ejecuto mi aplicativo con tomcat 5.0 y sale el siguiente error en el log del tomcat:
      ================================================
      2006-05-27 18:19:33 StandardContext[/balancer]org.apache.webapp.balancer.BalancerFilter: init(): ruleChain: [org.apache.webapp.balancer.RuleChain: [org.apache.webapp.balancer.rules.URLStringMatchRule: Target string: News / Redirect URL: http://www.cnn.com], [org.apache.webapp.balancer.rules.RequestParameterRule: Target param name: paramName / Target param value: paramValue / Redirect URL: http://www.yahoo.com], [org.apache.webapp.balancer.rules.AcceptEverythingRule: Redirect URL: http://jakarta.apache.org]]
      2006-05-27 18:19:44 StandardContext[/jsp-examples]ContextListener: contextInitialized()
      2006-05-27 18:19:44 StandardContext[/jsp-examples]SessionListener: contextInitialized()
      2006-05-27 18:19:45 StandardContext[/servlets-examples]ContextListener: contextInitialized()
      2006-05-27 18:19:45 StandardContext[/servlets-examples]SessionListener: contextInitialized()
      2006-05-27 18:19:48 StandardContext[/WebSiteAdministracion]Loading Spring root WebApplicationContext
      2006-05-27 18:19:50 StandardContext[/WebSiteAdministracion]Excepción enviando evento inicializado de contexto a instancia de escuchador de clase org.springframework.web.context.ContextLoaderListener
      org.springframework.beans.factory.BeanDefinitionStoreException: Error registering bean with name 'ubigeoDao' defined in ServletContext resource [/WEB-INF/spring-context-dao.xml]: Bean class [com.empresa.web.administracion.modelo.spring.daoimpl.UbigeoDaoImpl] not found; nested exception is java.lang.ClassNotFoundException: com.empresa.web.administracion.modelo.spring.daoimpl.UbigeoDaoImpl
      java.lang.ClassNotFoundException: com.empresa.web.administracion.modelo.spring.daoimpl.UbigeoDaoImpl
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1340)
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1189)
      at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:219)
      at org.springframework.util.ClassUtils.forName(ClassUtils.java:109)
      at org.springframework.beans.factory.support.BeanDefinitionReaderUtils.createBeanDefinition(BeanDefinitionReaderUtils.java:65)
      at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.parseBeanDefinitionElement(DefaultXmlBeanDefinitionParser.java:466)
      at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.parseBeanDefinitionElement(DefaultXmlBeanDefinitionParser.java:432)
      at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.parseBeanDefinitions(DefaultXmlBeanDefinitionParser.java:347)
      at org.springframework.beans.factory.xml.DefaultXmlBeanDefinitionParser.registerBeanDefinitions(DefaultXmlBeanDefinitionParser.java:197)
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:295)
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:223)
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:173)
      at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:148)
      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:129)
      at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:145)
      at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:126)
      at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
      at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:89)
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:262)
      at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:139)
      at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:252)
      at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:190)
      at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
      at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3827)
      at org.apache.catalina.core.StandardContext.start(StandardContext.java:4343)
      at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:823)
      at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:807)
      at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:595)
      at org.apache.catalina.core.StandardHostDeployer.install(StandardHostDeployer.java:277)
      at org.apache.catalina.core.StandardHost.install(StandardHost.java:832)
      at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:701)
      at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:432)
      at org.apache.catalina.startup.HostConfig.start(HostConfig.java:983)
      at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:349)
      at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1091)
      at org.apache.catalina.core.StandardHost.start(StandardHost.java:789)
      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1083)
      at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:478)
      at org.apache.catalina.core.StandardService.start(StandardService.java:480)
      at org.apache.catalina.core.StandardServer.start(StandardServer.java:2313)
      at org.apache.catalina.startup.Catalina.start(Catalina.java:556)
      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:324)
      at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:287)
      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:425)

      2006-05-27 18:19:50 StandardContext[/WebSiteAdministracion]Closing Spring root WebApplicationContext

      ==============================================
      Nota: este tomcat usa el servlet 4.0 y jsp 2.0
      ==============================================

      Por favor como podria solucionar el problema???