小编ric*_*ver的帖子

使用Spring,在web.xml中映射到root,找不到静态资源

我要做的是将请求映射到servlet根目录(正确的术语?).我正处于将URL映射到正确视图的位置,但无法找到作为页面一部分的所有静态内容--css,javascript,images.

所以在我的web.xml中,我的servlet标签看起来像这样

<servlet-mapping>
    <servlet-name>springapp</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)

我的控制器看起来像这样:

@RequestMapping("/shop")
public class TheShopController extends MyBaseController {

    public static String VIEW = "Tile.Shop";

    @Override
    @RequestMapping(method = RequestMethod.GET)
    protected ModelAndView processRequest(HttpServletRequest req, HttpServletResponse resp) {
        ModelAndView mav = new ModelAndView(VIEW);
        return mav;
    }

}
Run Code Online (Sandbox Code Playgroud)

MyBaseController非常简单.它看起来像这样:

public abstract class MyBaseController extends AbstractController {

    protected Logger log = Logger.getLogger(getClass());

    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest req, HttpServletResponse resp) 
        throws Exception {

        ModelAndView mav = processRequest(req, resp);
        return mav;
    }

    protected abstract ModelAndView processRequest(HttpServletRequest req, HttpServletResponse resp);
}
Run Code Online (Sandbox Code Playgroud)

我在视图层中使用Tiles.我的配置如下: …

model-view-controller spring tiles

29
推荐指数
2
解决办法
6万
查看次数

Spring拒绝bean名称,没有指定URL路径

我试图使用注释驱动的控制器配置注册拦截器.据我所知,我已经完成了所有事情但是当我尝试测试拦截器时没有任何反应.查看日志后,我发现以下内容:

2010-04-04 20:06:18,231 DEBUG [main] support.AbstractAutowireCapableBeanFactory (AbstractAutowireCapableBeanFactory.java:452) - Finished creating instance of bean     'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0'
2010-04-04 20:06:18,515 DEBUG [main] handler.AbstractDetectingUrlHandlerMapping (AbstractDetectingUrlHandlerMapping.java:86) - Rejected bean name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0': no URL paths identified
2010-04-04 20:06:19,109 DEBUG [main] support.AbstractBeanFactory (AbstractBeanFactory.java:241) - Returning cached instance of singleton bean 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0'
Run Code Online (Sandbox Code Playgroud)

查看此日志片段的第二行.Spring是否拒绝DefaultAnnotationHandlerMapping bean?如果是这样,这可能是我的拦截器无法正常工作的问题?

这是我的应用程序上下文:

<?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:p="http://www.springframework.org/schema/p"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:mvc="http://www.springframework.org/schema/mvc"       
   xsi:schemaLocation="
        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
        http://www.springframework.org/schema/mvc 
        http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd"
 default-autowire="byName"> 

 <!-- Configures the @Controller programming model -->
<mvc:annotation-driven />

<!-- Scan for annotations... -->
<context:component-scan base-package="
    com.splash.web.controller, …
Run Code Online (Sandbox Code Playgroud)

java spring spring-mvc

10
推荐指数
2
解决办法
3万
查看次数

Spring:使用@Controller注释的控制器继承

我希望能够在我的Spring应用程序中创建一个基本控制器,除其他外,它确定用户是否是注册用户.遵循模板设计模式的此基本控制器将包含控制器子类将实现的抽象受保护方法.

抽象方法会将一个User实例传递给它,注册或以其他方式.但是,我不知道如何做到这一点,因为通过使用纯粹使用@Controller注释的控制器,每个控制器都可以自由地定义他们的请求处理方法.

是否会创建一种注入每个控制器并用于验证用户的某种用户服务类是解决此问题的一种方法?这引出了一个问题(至少对我而言)这样的控制器是如何获得HttpServletRequest或Session对象的?

谢谢.

spring annotations controller single-table-inheritance

7
推荐指数
2
解决办法
9605
查看次数

如何包装异步类以使其同步?使用NSRunLoop?

我目前正在开发一个iPhone应用程序,我有一个来自第三方的库,它有异步行为,但是我想用自己的类包装并使它看起来是同步的.

这个库中的中心类,我们称之为Connection类,有几个函数在调用委托类的实例上的方法时解析它们的最终结果.我正在尝试做的是包装这个类和委托,使它看起来是同步的而不是异步的.如果我在Java中这样做,我会使用FutureTask或CountdownLatch或只是join().但我不确定目标C中最好的方法.

我首先创建了一个NSThread扩展,NFCThread,它符合上面提到的委托协议.我的想法是我将init和NFCThread,将NFCThread实例传递给Connection的setDelegate方法,启动线程然后在Connection上调用异步方法.我的期望是NFCThread实例上的三个委托方法之一将被调用,最终导致线程退出.

为了模拟连接,我做了以下操作.我在NFCThread中添加了一个NSConditionalLock:

joinLock = [[NSConditionLock alloc] initWithCondition:NO];
Run Code Online (Sandbox Code Playgroud)

调用Connection的代码看起来像这样:

NFCThread *t = [[NFCThread alloc] init];
[connection setDelegate:t];
[t start];

[connection openSession];
// Process errors, etc...

[t.joinLock lockWhenCondition:YES];
[t.joinLock unlock];
[t release];
[connection setDelegate:nil];
Run Code Online (Sandbox Code Playgroud)

委托的协议有三种方法.在NFCThread中我实现了每个方法,如下所示:

- (void)didReceiveMessage:(CommandType)cmdType 
                     data:(NSString *)responseData 
               length:(NSInteger)length {
    NSLog(@"didReceiveMessage");
    // Do something with data and cmdType...
    [joinLock lock];
    [joinLock unlockWithCondition:YES];
    callBackInvoked = YES;
}
Run Code Online (Sandbox Code Playgroud)

我重载了NFCThread的主要方法,以便它不断循环.像这样的东西:

while (!callBackInvoked) { ; }
Run Code Online (Sandbox Code Playgroud)

我发现这不是一个好主意,因为它会导致cpu使用率通过屋顶.所以我尝试使用我在这个网站上找到的一些例子的运行循环:

NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
[runLoop addPort:[NSMachPort port] forMode:NSDefaultRunLoopMode];

while (!callBackInvoked) {
    [runLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]; …
Run Code Online (Sandbox Code Playgroud)

multithreading objective-c nsrunloop

6
推荐指数
1
解决办法
3639
查看次数

XCode 4:删除顶级文件夹

我不小心将一个文件夹添加到工作区的顶层,因为它显示在XCode 4中.也就是说,该文件夹现在位于顶层的项目旁边,我想删除它但是我不喜欢它不知道怎么做.我尝试时禁用删除选项.我在某个地方读到了创建工作区后可以删除这样的文件夹.我想暂时避免这种情况.

此文件夹的元数据是否存储在project.pbxproj文件中?我需要检查我对project.pbxproj文件所做的更改,而不是我正在尝试删除的顶级文件夹的元数据.

谢谢.

xcode4

4
推荐指数
1
解决办法
866
查看次数