我最近的任务是开始构建一个新的Spring 3 MVC项目(我在这方面非常棒)。在开普勒建立了大部分POC项目后,我有:
... 12:46:21.916 [http-apr-8080-exec-5] TRACE o.s.w.s.v.InternalResourceViewResolver - Cached view [home] 12:46:21.916 [http-apr-8080-exec-5] DEBUG o.s.web.servlet.DispatcherServlet - Rendering view [org.springframework.web.servlet.view.JstlView: name 'home'; URL [/WEB-INF/view/home.jsp]] in DispatcherServlet with name 'sample' 12:46:21.916 [http-apr-8080-exec-5] TRACE o.s.web.servlet.view.JstlView - Rendering view with name 'home' with model {name=lingxotika.org} and static attributes {} 12:46:21.916 [http-apr-8080-exec-5] DEBUG o.s.web.servlet.view.JstlView - Added model object 'name' of type [java.lang.String] to request in view with name 'home' 12:46:21.921 [http-apr-8080-exec-5] DEBUG o.s.web.servlet.view.JstlView - Forwarding to resource [/WEB-INF/view/home.jsp] in InternalResourceView 'home' 12:46:21.957 [http-apr-8080-exec-5] TRACE o.s.web.servlet.DispatcherServlet - Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@1bb3db1b 12:46:21.960 [http-apr-8080-exec-5] DEBUG o.s.web.servlet.DispatcherServlet - Successfully completed request 12:46:21.960 [http-apr-8080-exec-5] TRACE o.s.w.c.s.AnnotationConfigWebApplicationContext - Publishing event in WebApplicationContext for namespace 'sample-servlet': ServletRequestHandledEvent: url=[/codetutr/home/]; client=[127.0.0.1]; method=[GET]; servlet=[sample]; session=[0108E781644C1268FD92C11BD78888FB]; user=[null]; time=[87ms]; status=[OK]
Logger
类方法时(我已经尝试了两种方法)
Eclipse,org.slf4j.Logger
和ch.qos.logback.classic
风格)
无法识别Logger实例中的方法:
package org.lingxotika.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class SampleController {
static final Logger log = LoggerFactory.getLogger(SampleController.class);
log.info("Hit Controller..."); // Error is here
@RequestMapping("home")
public String loadHomePage(Model model) {
model.addAttribute("name", "lingxotika.org");
return "home";
}
}
键入log.
后的Eclipse Code Assist显示以下选项(抱歉,无法发布截图):
new - create new object
nls - non-externalized string marker
runnable - runnable
toarray - convert collection to array
总之,我已经看到示例here和here表明这不是Spring的限制或我承认缺乏能力,而是我忽略的Eclipse问题。我避免发布可能无关的信息,但我很乐意提供任何进一步的代码,日志或配置示例。任何帮助将不胜感激。
答案 0 :(得分:1)
好像你的项目中没有slf4j api jar。
因为它在tomcat中工作,所以tomcat可能正在使用“提供的”jar,即:一个是tomcat应用程序的一部分。
如果您正在使用maven,则需要在pom中具有以下依赖关系:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>