gpt4 book ai didi

java - 无法将 Spring MVC 依赖项添加到 Maven 项目

转载 作者:行者123 更新时间:2023-12-02 13:36:06 25 4
gpt4 key购买 nike

我是 Spring Mvc 新手..我正在尝试创建一个基于 Maven 的 Spring Mvc 演示..

基本的“hello world”演示工作正常。当我点击“http://localhost:8080/SampleRestful/”时,它会打印“Hello World”

但是,当我将 spring-webmvc 依赖项添加到我的 pom.xml 并在服务器上运行它时,它会在点击“http://localhost:8080/SampleRestful/ ”时抛出错误 404 .

这是 pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.promact.maven</groupId>
<artifactId>SampleRestful</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>SampleRestful Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.3.0.RELEASE</version>
</dependency>

</dependencies>
<build>
<finalName>SampleRestful</finalName>
</build>
</project>

这是错误日志:

    Mar 24, 2017 12:19:48 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version: Apache Tomcat/8.5.8
Mar 24, 2017 12:19:48 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built: Nov 3 2016 21:14:13 UTC
Mar 24, 2017 12:19:48 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number: 8.5.8.0
Mar 24, 2017 12:19:48 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name: Windows 7
Mar 24, 2017 12:19:48 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version: 6.1
Mar 24, 2017 12:19:48 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture: amd64
Mar 24, 2017 12:19:48 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home: C:\Program Files\Java\jdk1.8.0_92\jre
Mar 24, 2017 12:19:48 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version: 1.8.0_92-b14
Mar 24, 2017 12:19:48 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor: Oracle Corporation
Mar 24, 2017 12:19:48 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE: D:\SpringWorkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Mar 24, 2017 12:19:48 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME: C:\Program Files\Apache Software Foundation\Tomcat 8.5
Mar 24, 2017 12:19:48 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=D:\SpringWorkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Mar 24, 2017 12:19:48 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=C:\Program Files\Apache Software Foundation\Tomcat 8.5
Mar 24, 2017 12:19:48 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=D:\SpringWorkspace
Mar 24, 2017 12:19:48 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=C:\Program Files\Apache Software Foundation\Tomcat 8.5\endorsed
Mar 24, 2017 12:19:48 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=Cp1252
Mar 24, 2017 12:19:48 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.8.0_92\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files/Java/jre1.8.0_92/bin/server;C:/Program Files/Java/jre1.8.0_92/bin;C:/Program Files/Java/jre1.8.0_92/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\webserver\ImageMagick;C:\Program Files (x86)\ImageMagick-6.8.1-Q16;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Python27;D:\Nishant\Android\android-sdk\platform-tools;D:\Nishant\Android\android-sdk\tools;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files (x86)\Ant 1.8\bin;C:\Program Files (x86)\Ant 1.8\lib;C:\Program Files\Java\jdk1.7.0_06\bin;C:\Program Files\Java\jdk1.6.0_30\bin;C:\Program Files\OpenSSL\bin;C:\webserver\MySQL\bin;C:\Ruby193\bin;C:\Users\nishant\Downloads\libs\depot_tools\;D:\Nishant\Android\android-ndk-r8e\;C:\Python27\;C:\Python27\Scripts\;C:\Program Files\gradle-2.1-all\gradle-2.1\bin\;C:\Program Files\TortoiseGit\bin;C:\Users\m\AppData\Local\GitHub\PortableGit_054f2e797ebafd44a30203088cd3d58663c627ef\bin;D:\setups\apache-ant-1.9.4\bin;C:\Program Files\nodejs;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Java\jdk1.8.0_92\bin\;C:\Program Files\Java\jdk1.8.0_92\;C:\Program Files\nodejs\;D:\setups\java\apache-maven-3.3.9\bin;C:\Users\m\AppData\Roaming\npm;C:\Users\m\AppData\Local\atom\bin;D:\setups\java\spring-tool-suite-3.8.2.RELEASE-e4.6.1-win32-x86_64\sts-bundle\sts-3.8.2.RELEASE;;.
Mar 24, 2017 12:19:49 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Mar 24, 2017 12:19:49 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Mar 24, 2017 12:19:49 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Mar 24, 2017 12:19:49 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Mar 24, 2017 12:19:49 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 835 ms
Mar 24, 2017 12:19:49 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Mar 24, 2017 12:19:49 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.5.8
Mar 24, 2017 12:19:49 PM org.apache.catalina.util.SessionIdGeneratorBase createSecureRandom
INFO: Creation of SecureRandom instance for session ID generation using [SHA1PRNG] took [110] milliseconds.
Mar 24, 2017 12:19:49 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor D:\SpringWorkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf\Catalina\localhost\SampleRestful.xml
Mar 24, 2017 12:19:49 PM org.apache.catalina.startup.SetContextPropertiesRule begin
WARNING: [SetContextPropertiesRule]{Context} Setting property 'source' to 'org.eclipse.jst.j2ee.server:SampleRestful' did not find a matching property.
Mar 24, 2017 12:19:49 PM org.apache.catalina.core.ContainerBase addChildInternal
SEVERE: ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/SampleRestful]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:596)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1805)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.LifecycleException: Failed to initialize component [org.apache.catalina.webresources.StandardRoot@3f797939]
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:112)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:140)
at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:4842)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:4974)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 10 more
Caused by: org.apache.catalina.LifecycleException: Failed to initialize component [org.apache.catalina.webresources.DirResourceSet@572b1df8]
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:112)
at org.apache.catalina.webresources.StandardRoot.initInternal(StandardRoot.java:675)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:107)
... 14 more
Caused by: java.lang.IllegalArgumentException: The directory specified by base and internal path [D:\SpringWorkspace\SampleRestful\target\m2e-wtp\web-resources]\[] does not exist.
at org.apache.catalina.webresources.DirResourceSet.checkType(DirResourceSet.java:251)
at org.apache.catalina.webresources.AbstractFileResourceSet.initInternal(AbstractFileResourceSet.java:145)
at org.apache.catalina.webresources.DirResourceSet.initInternal(DirResourceSet.java:259)
at org.apache.catalina.util.LifecycleBase.init(LifecycleBase.java:107)
... 16 more

Mar 24, 2017 12:19:49 PM org.apache.catalina.startup.HostConfig deployDescriptor
SEVERE: Error deploying configuration descriptor D:\SpringWorkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf\Catalina\localhost\SampleRestful.xml
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/SampleRestful]]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:756)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:596)
at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1805)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

Mar 24, 2017 12:19:49 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deployment of configuration descriptor D:\SpringWorkspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\conf\Catalina\localhost\SampleRestful.xml has finished in 15 ms
Mar 24, 2017 12:19:49 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler [http-nio-8080]
Mar 24, 2017 12:19:49 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler [ajp-nio-8009]
Mar 24, 2017 12:19:49 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 632 ms

我无法找到问题背后的原因。请帮忙..!! :(

最佳答案

Spring MVC 不能单独使用,它需要其他依赖项,例如:Spring-core、Spring-context、Spring-beans 和 Spring-web。

如果您想启动一个新的 SpringMVC 项目,我建议您按照以下步骤操作(这就是我启动新的 SpringMVC 项目时所做的操作):

1) 将 Spring Tool Suite 添加到 Eclipse(转到“帮助”(菜单)->Eclipse Marketplace->(在查找搜索栏中)输入“STS”并安装它。

2)然后在Eclipse中,转到File->Spring Legacy Project->Spring MVC Project(输入项目名称),单击下一步,输入包名称并完成。

您将拥有一个可以正常工作的预配置 Spring MVC 项目。我建议你更改Java和其他依赖项的版本。

希望这对您有帮助。

关于java - 无法将 Spring MVC 依赖项添加到 Maven 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42993347/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com