简体   繁体   English

从Eclipse部署到tomcat时的Spring配置问题

[英]Spring configuration issue while deploy to tomcat from eclipse

I have issue most probably with either Eclipse or Tomcat. 我最有可能与Eclipse或Tomcat有关。 Because if I make package proj.war from console and then deploy to local Tomcat instance. 因为如果我从控制台制作包proj.war,然后将其部署到本地Tomcat实例。 It works fine. 工作正常。 But when I try to run to server from Eclipse I got error as :- 但是,当我尝试从Eclipse运行到服务器时,出现了如下错误:-

Nov 15, 2015 8:00:30 AM org.apache.catalina.core.StandardContext listenerStart 2015年11月15日,上午8:00:30 org.apache.catalina.core.StandardContext listenerStart

SEVERE: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener 严重:配置类org.springframework.web.context.ContextLoaderListener的应用程序侦听器时出错

java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1333 java.lang.ClassNotFoundException:org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1333上的org.springframework.web.context.ContextLoaderListener

I got 2 questions. 我有两个问题。 How to fix this deployment? 如何解决此部署? I'm ok with manual console build and deployment. 我可以手动进行控制台构建和部署。 But if I manually deploy my package to Tomcat, how can I debug? 但是,如果我将程序包手动部署到Tomcat,该如何调试? I have both eclipse and intellij. 我既有月食又有智慧。 How can I debug after manual build and deployment? 手动构建和部署后如何调试?

Please also check the picture to verify my project structure is ok in Eclipse? 还请检查图片以验证我的项目结构在Eclipse中可以吗?

问题截图

I had a similar problem when running a spring web application in an Eclipse managed tomcat. 在Eclipse托管的Tomcat中运行spring Web应用程序时,我遇到了类似的问题。 I solved this problem by adding maven dependencies in the project's web deployment assembly. 我通过在项目的Web部署程序集中添加Maven依赖关系来解决此问题。

  1. Open the project's properties (eg, right-click on the project's name in the project explorer and select "Properties"). 打开项目的属性(例如,在项目浏览器中右键单击项目的名称,然后选择“属性”)。
  2. Select "Deployment Assembly". 选择“部署程序集”。
  3. Click the "Add..." button on the right margin. 单击右边的“添加...”按钮。
  4. Select "Java Build Path Entries" from the menu of Directive Type and click "Next". 从“指令类型”菜单中选择“ Java构建路径条目”,然后单击“下一步”。
  5. Select "Maven Dependencies" from the Java Build Path Entries menu and click "Finish". 从Java Build Path Entries菜单中选择“ Maven Dependencies”,然后单击“ Finish”。

You should see "Maven Dependencies" added to the Web Deployment Assembly definition. 您应该看到“ Maven依赖关系”已添加到Web部署程序集定义中。

maybe you have missed some jars. 也许您错过了一些罐子。

I think you should do the manual deployment to avoid these problems. 我认为您应该手动部署以避免这些问题。 IntelliJ provides Run configurations for maven project. IntelliJ为maven项目提供运行配置。 You can deploy the application just by one click. 您可以一键部署应用程序。 To debug application host on Tomcat from IntelliJ. 从IntelliJ在Tomcat上调试应用程序主机。 You do the following steps: 1. create file TOMCAT_HOME/bin/setenv.sh. 您执行以下步骤:1.创建文件TOMCAT_HOME / bin / setenv.sh。 The content of this file should be: 该文件的内容应为:

export JPDA_OPTS="-agentlib:jdwp=transport=dt_socket,address=1043,server=y,suspend=n"
  1. On IntelliJ, choose Run > Edit Configurations. 在IntelliJ上,选择“运行”>“编辑配置”。 Click the "+" icon to add a new "Remote" configuration. 单击“ +”图标添加新的“远程”配置。 Leave everything as default but the port. 将所有内容保留为默认值,但保留端口。 Change it to 1043. 将其更改为1043。

Now when tomcat started, you can debug the application by choose Run > Debug... Then choose the configuration you just created in step 2. 现在,当tomcat启动时,您可以通过选择Run> Debug ...来调试应用程序,然后选择您在步骤2中刚刚创建的配置。

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

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