简体   繁体   English

Spring MVC 应用程序在 Eclipse 中运行但不是 Intellij - 404 Not Found

[英]Spring MVC App runs in Eclipse but not Intellij - 404 Not Found

I've written a Spring MVC app that is functional on an app server.我编写了一个在应用服务器上运行的 Spring MVC 应用程序。 I'm attempting to switch development of this app from Eclipse and to Intellij.我正在尝试将此应用程序的开发从 Eclipse 切换到 Intellij。 I am very new to the IDE so I'm not sure where I have gone wrong here.我对 IDE 很陌生,所以我不确定我在这里出了什么问题。

When I run this application on the server in Eclipse it goes to localhost just fine and works as expected.当我在 Eclipse 中的服务器上运行此应用程序时,它会很好地转到 localhost 并按预期工作。 I created a run configuration in IntelliJ, the app compiles and the server log says it was deployed successfully.我在 IntelliJ 中创建了一个运行配置,应用程序编译并且服务器日志显示它已成功部署。

However in the browser it gives the standard HTTP Status 404 - Resource Not Available.但是在浏览器中,它给出了标准的 HTTP 状态 404 - 资源不可用。

I really don't think it's the servlet or web.xml because those are working just fine in Eclipse.我真的不认为这是 servlet 或 web.xml 因为它们在 Eclipse 中工作得很好。 I've also created a brand new app in Intellij to test it and it works fine.我还在 Intellij 中创建了一个全新的应用程序来测试它并且它运行良好。 So it must be something specific to IntelliJ that I have misconfigured or not setup at all...any ideas?所以它一定是我配置错误或根本没有设置的特定于 IntelliJ 的东西......有什么想法吗? Let me know if you need to see specific screens or anything.如果您需要查看特定屏幕或任何内容,请告诉我。

So after toying with this, making it worse a few times, and then getting it back to the original 404 I found the difference.所以在玩弄这个之后,让它变得更糟几次,然后把它恢复到原来的 404,我发现了不同之处。

Eclipse has an internal tomcat server it runs projects on, Intellij runs its projects on the default tomcat server installed on your computer. Eclipse 有一个内部的 tomcat 服务器,它在上面运行项目,Intellij 在你计算机上安装的默认 tomcat 服务器上运行它的项目。 Intellij exports the project you are running to the server in the web apps folder as the name of your project. Intellij 将您正在运行的项目作为项目名称导出到 Web 应用程序文件夹中的服务器。

So after I found that, in my tomcat run configuration in Intellij I had to specifiy the application context.因此,在我发现之后,在 Intellij 中的 tomcat 运行配置中,我必须指定应用程序上下文。 Edit Configurations -> Deployment tab -> Application context, and set it to / YourProjectName .编辑配置 -> 部署选项卡 -> 应用程序上下文,并将其设置为 / YourProjectName My guess is that this tells tomcat where to find your project within the web apps folder.我的猜测是,这会告诉 tomcat 在 web 应用程序文件夹中的何处找到您的项目。

I hope this can help anyone else who is a relative beginner to tomcat/java EE and intellij like I am.我希望这可以帮助任何像我一样是 tomcat/java EE 和 intellij 相对初学者的人。

intellij 中有一个名为“Smart Tomcat”的插件,它允许以更少的配置运行 spring 或 web 应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM