小编典典

原始服务器找不到目标资源的当前表示,或者不愿意透露该资源的存在。在部署到tomcat

spring

我已经使用带有Eclipse IDE的Spring构建了一个应用程序。当我从Eclipse IDE启动项目时,一切都很好,但是当我将maven项目打包为war文件并部署到单独的tomcat时,我遇到了这个问题

The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

这是我的xml文件中的配置代码段

<!-- View Resolver -->
    <beans:bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/pages/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>

我正在尝试访问此控制器

@RequestMapping(value = {"/welcome", "/"})
    public String defaultPage() {
            return "Web Service data successfuly consumed";


    }

有人知道为什么在部署到tomcat时会失败吗?


阅读 5671

收藏
2020-04-18

共2个答案

小编典典

如果你正在开发Spring Boot应用程序,请在主文件中添加“ SpringBootServletInitializer”,如以下代码所示。因为如果没有SpringBootServletInitializer,Tomcat会将其视为普通应用程序,则不会将其视为Spring引导应用程序。

@SpringBootApplication
public class DemoApplication extends *SpringBootServletInitializer*{

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
         return application.sources(DemoApplication .class);
    }

    public static void main(String[] args) {
         SpringApplication.run(DemoApplication .class, args);
    }
}
2020-04-18
小编典典

我为此问题挣扎过很多次。

我当前使用的解决方案是在webapp(或保存了jsp之类的视图的文件夹)处于部署程序集下。

这样做Right click on the project > Build Path > Configure Build path > Deployment Assembly > Add(right hand side) > Folder > (add your jsp文件夹。在默认情况下为src/main/webapp)

在你做完所有正确的事情之后,你也可能会收到此错误,但是在JSP上,你将锚标记放置为旧的样式(如果有其他问题,我会添加此标签以防其他人)。

我在jsp上具有以下语法。<a href="/mappedpath">TakeMeToTheController</a>而且我一直看到问题中提到的错误。但是,将标签更改为如下所示的标签可以解决此问题。

<a href=" <spring:url value="/mappedpath" /> ">TakeMeToTheController</a>
2020-04-18