Erro Spring MVC

7 respostas
kaahxd

Bem, estava evitando abrir um novo tópico porém não estou conseguindo de jeito nenhum fazer o Spring funcionar na minha aplicação teste :cry:
Segue os arquivos do projeto teste:

Controller
package br.com.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class TesteController {
	@RequestMapping("/ola")
	public String ola() {
		System.out.println("Funciona Spring MVC");
		return "ok";
	}
}
spring.xml
<?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:mvc="http://www.springframework.org/schema/mvc"
	xsi:schemaLocation="http://www.springframework.org/schema/mvc 
						http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
						http://www.springframework.org/schema/beans 
						http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
						http://www.springframework.org/schema/context 
						http://www.springframework.org/schema/context/spring-context-3.0.xsd">

	<context:component-scan base-package="br.com" />
	<mvc:annotation-driven />

	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/WEB-INF/views/"/>
		<property name="suffix" value=".jsp"/>
	</bean>

</beans>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>TesteHiberJSP</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>lista.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
  
</web-app>

E finalmente o erro

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Servlet.init() for servlet springmvc threw exception
	org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
	org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
	org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
	org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
	org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
	org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
	java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
	java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
	java.lang.Thread.run(Thread.java:679)

root cause

java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V
	org.apache.commons.logging.impl.SLF4JLocationAwareLog.debug(SLF4JLocationAwareLog.java:133)
	org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:109)
	javax.servlet.GenericServlet.init(GenericServlet.java:160)
	org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
	org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
	org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
	org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
	org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:166)
	org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
	java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
	java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
	java.lang.Thread.run(Thread.java:679)

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.12 logs.

Alguma ideia do que está acontecendo?

7 Respostas

wagnerfrancisco

O erro é relativo às APIs de log. Você tem as libs slf4j-api, log4j e slf4j-log4j no build path?

kaahxd

/TesteHiberJSP/WebContent/WEB-INF/lib/antlr-2.7.6.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/aopalliance-1.0.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/commons-collections-3.1.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/dom4j-1.6.1.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/hibernate3.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/hibernate-jpa-2.0-api-1.0.0.Final.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/javassist-3.9.0.GA.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/jcl-over-slf4j-1.6.1.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/joda-time-2.0.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/jstl-api-1.2.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/jstl-impl-1.2.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/jta-1.1.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/log4j-1.2.16.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/mysql-connector-java-5.1.7-bin.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/slf4j-api-1.6.1.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/slf4j-log4j12-1.5.8.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/spring-aop-3.0.6.RELEASE.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/spring-asm-3.0.6.RELEASE.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/spring-beans-3.0.6.RELEASE.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/spring-context-3.0.6.RELEASE.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/spring-context-support-3.0.6.RELEASE.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/spring-core-3.0.6.RELEASE.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/spring-expression-3.0.6.RELEASE.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/spring-web-3.0.6.RELEASE.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/spring-webmvc-3.0.6.RELEASE.jar

Segue a lista do meu Build Path

wagnerfrancisco

Veja se usar as mesmas versões destes dois resolve:

/TesteHiberJSP/WebContent/WEB-INF/lib/slf4j-api-1.6.1.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/slf4j-log4j12-1.5.8.jar

kaahxd

/TesteHiberJSP/WebContent/WEB-INF/lib/antlr-2.7.6.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/aopalliance-1.0.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/commons-collections-3.1.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/dom4j-1.6.1.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/hibernate3.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/hibernate-jpa-2.0-api-1.0.0.Final.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/javassist-3.9.0.GA.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/jcl-over-slf4j-1.6.1.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/joda-time-2.0.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/jstl-api-1.2.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/jstl-impl-1.2.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/jta-1.1.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/log4j-1.2.16.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/mysql-connector-java-5.1.7-bin.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/slf4j-api-1.6.1.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/slf4j-log4j12-1.6.1.jar

/TesteHiberJSP/WebContent/WEB-INF/lib/spring-aop-3.0.6.RELEASE.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/spring-asm-3.0.6.RELEASE.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/spring-beans-3.0.6.RELEASE.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/spring-context-3.0.6.RELEASE.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/spring-context-support-3.0.6.RELEASE.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/spring-core-3.0.6.RELEASE.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/spring-expression-3.0.6.RELEASE.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/spring-web-3.0.6.RELEASE.jar
/TesteHiberJSP/WebContent/WEB-INF/lib/spring-webmvc-3.0.6.RELEASE.jar

Porém o erro permanece o mesmo =(

romarcio

Tenta trocar a versão das libs, você está usando a 1.6, troca pela 1.5.
Outra coisa, esse erro acontece em tempo de execução, se não me engano, então veja se no servidor você já não tem essas lib, pode estar dando conflito.

kaahxd

romarcio é isso mesmo que você falou, estava com um problema de conflito, muito obrigado!

romarcio

:thumbup:
Coloca seu post como resolvido. Edita a primeira postagem e ao lado do titulo escreva [Resolvido]
T+

Criado 27 de agosto de 2012
Ultima resposta 27 de ago. de 2012
Respostas 7
Participantes 3