java - 将 Spring 应用程序发布到 Geronimo Web 服务器时出错

标签 java spring spring-mvc geronimo

我正在尝试使用 Geronimo Web 服务器设置 Spring,但出现以下错误:

2010-10-08 18:52:45,105 WARN  [PathMatchingResourcePatternResolver] Cannot search for matching files underneath URL [bundle://316.0:1/com/unveiled/politics/] because it does not correspond to a directory in the file system
java.io.FileNotFoundException: URL [bundle://316.0:1/com/unveiled/politics/] cannot be resolved to absolute file path because it does not reside in the file system: bundle://316.0:1/com/unveiled/politics/
 at org.springframework.util.ResourceUtils.getFile(ResourceUtils.java:204)
 at org.springframework.core.io.AbstractFileResolvingResource.getFile(AbstractFileResolvingResource.java:51)
 at org.springframework.core.io.UrlResource.getFile(UrlResource.java:168)
...

这个应用程序似乎可以在 JBoss AS 上运行。

其他一些重要的配置文件:

网络.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <!-- Handles all requests into the application -->
    <servlet>
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                /WEB-INF/spring/app-config.xml
            </param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

</web-app>

应用程序配置文件:

<?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"
    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">

    <!-- Scans the classpath of this application for @Components to deploy as beans -->
    <context:component-scan base-package="com.unveiled.politics" />

    <!-- Configures Spring MVC -->
    <import resource="mvc-config.xml" />

</beans>

mvc-config.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: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/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

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

    <!-- Resolves view names to protected .jsp resources within the /WEB-INF/views directory -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/views/"/>
        <property name="suffix" value=".jsp"/>
    </bean>

</beans>

欢迎 Controller .java:

package com.unveiled.politics.controllers;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class WelcomeController {
    @RequestMapping(value="welcome", method = RequestMethod.GET)
    public String getWelcomePage(ModelMap model) {
        return "index";
    }
}

最佳答案

组件扫描仅在应用程序(无论是 EAR 还是 WAR)被应用程序解包到文件系统时才起作用。出于运行时性能原因,应用服务器通常无论如何都会这样做。

看起来您的 Geronimo 服务器没有执行此操作。希望在某处有一个设置,您可以在其中配置为在运行应用程序之前将其解压缩。

关于java - 将 Spring 应用程序发布到 Geronimo Web 服务器时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3895392/

相关文章:

javascript - Spring MVC - 使用 Javascript 设置 actionURL 参数

java - 为什么当我添加productimage代码和 "productname"ProductNAME时不支持 "NULL not allowed for column "; SQL语句:"

java - Spring MVC 项目的可选 redis session 存储

java - 围绕现有数据值类的 lombok 构建器

java - 如何为小程序配置新的安全对话框?

java - SnakeYAML 低级 API 无法正确解析 MapNode

java - 从 tomcat sprinf 应用程序获取 pdf 文件时不允许加载本地资源

java - 在 spring-boot 中将 hashmap 转换为 json 字符串

java - 有没有办法在Java 8中将ZoneOffset转换为ZoneId?

java - 用于 portlet 的 Spring MVC,请求生命周期