我需要帮助获取 the spring PETCARE application使用 egit 和 m2e 插件在我的 eclipse/tomcat 安装中运行,我的机器上尚未安装这些插件。请注意,这不是 Spring 宠物诊所应用程序。这是我到目前为止所做的:
1.) I downloaded the spring PETCARE sample into eclipse kepler
using the eclipse egit plugin
2.) I then converted it to a maven project in eclipse and did
a maven update using the m2e plugin.
问题是我在文件 src/main/resources/META-INF/spring/appServlet/servlet-context.xml
中收到以下错误,表明 petcare:resources未找到
:
Multiple annotations found at this line:
- schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/petcare/spring-petcare-3.0.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
- cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'petcare:resources'.
我找到了this posting然后在我的 Eclipse 项目中的路径 myproject/src/main/resources/META-INF/spring.schemas 中找到 spring.schemas 文件。
spring.schemas
仅包含以下一行代码:
http\://www.springframework.org/schema/petcare/spring-petcare-3.0.xsd=org/springframework/samples/petcare/util/config/spring-petcare-3.0.xsd
谁能告诉我如何解决这个问题,以便解决错误消息并且我的应用程序可以编译?
即使是关于如何使用 egit 和 m2e 插件下载应用程序并将其安装到 eclipse 中的明确的分步说明也足够了。我们可以正确地从头开始,而不是从我当前遇到的错误中回溯。
<小时/>注意:除了已接受答案的内容之外,我还需要确保 Eclipse 使用 JDK 而不是 JRE,以便使用 Run 在 Eclipse 中成功启动应用程序作为..在服务器上运行。
最佳答案
petcare 命名空间的问题在于它无法通过架构位置 URL 在线获取。
Spring 在运行时使用 spring.schemas 文件解决了这个问题,但 Eclipse 不知道这个文件,也不知道如何使用它来查找 XSD。解决方案是使用 XML 目录在 eclipse 中手动配置 petcare 命名空间。
转到“首选项”,然后在“XML 目录”部分中配置命名空间,如下所示:
在位置中输入 xsd 文件 spring-petcare-3.0.xsd
的完整硬盘路径,选择 key 类型 架构位置
并作为 key 输入完整的 URL XSD:http://www.springframework.org/schema/petcare/spring-petcare-3.0.xsd
要确认其是否有效,请右键单击 servlet-context.xml 文件,然后单击“验证”。该文件不应再呈红色。
这是应用程序看起来正在运行的示例:
这是访问它的 URL:
http://localhost:20010/users/signin
要运行它,请执行以下步骤:
在 webapp/META-INF 中创建一个名为 context.xml 的文件
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/"/>
将其添加到 pom.xml 的 build/plugins 部分:
<plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <configuration> <port>20010</port> <path>/</path> </configuration> </plugin>
从命令行运行应用程序:
mvn clean install tomcat7:run-war -Dmaven.test.skip=true
运行日志:
INFO : org.springframework.integration.endpoint.EventDrivenConsumer - started org.springframework.integration.config.ConsumerEndpointFactoryBean#2
INFO : org.springframework.integration.endpoint.EventDrivenConsumer - started doctorMail.adapter
INFO : org.springframework.context.support.DefaultLifecycleProcessor - Starting beans in phase 0
INFO : org.springframework.web.servlet.DispatcherServlet - FrameworkServlet 'appServlet': initialization completed in 1661 ms
Feb 05, 2014 12:11:01 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-20010"]
使用上面的 URL 访问应用程序
您可以在 Eclipse 中创建一个 Maven 启动配置,将其作为 Maven 任务启动
关于java - 需要帮助安装和运行 Spring Petcare 示例应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21469791/