#java #spring #spring-mvc #xml-parsing
Вопрос:
Я использую проект на основе Spring MVC с использованием конфигураций xml, но при развертывании проекта я получаю ошибку ниже:-
09:57:14,050 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-5) MSC000001: Failed to start service jboss.deployment.unit."SpringMVC.war".PARSE: org.jboss.msc.service.StartException in service jboss.deployment.unit."SpringMVC.war".PARSE: WFLYSRV0153: Failed to process phase PARSE of deployment "SpringMVC.war"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:189)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1739)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.execute(ServiceControllerImpl.java:1701)
at org.jboss.msc.service.ServiceControllerImpl$ControllerTask.run(ServiceControllerImpl.java:1559)
at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
at java.lang.Thread.run(Unknown Source)
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYUT0027: Failed to parse XML descriptor "/D:/Development_Folder/jboss-eap-7.4/bin/content/SpringMVC.war/WEB-INF/web.xml" at [109,2]
at org.wildfly.extension.undertow.deployment.WebParsingDeploymentProcessor.deploy(WebParsingDeploymentProcessor.java:136)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:182)
... 8 more
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[109,2]
Message: Unexpected element '{http://java.sun.com/xml/ns/j2ee http://www.springframework.org/schema/security}global-method-security' encountered
at org.jboss.metadata.parser.util.MetaDataElementParser.unexpectedElement(MetaDataElementParser.java:115)
at org.jboss.metadata.parser.servlet.WebMetaDataParser.parse(WebMetaDataParser.java:196)
at org.jboss.metadata.parser.servlet.WebMetaDataParser.parse(WebMetaDataParser.java:51)
at org.wildfly.extension.undertow.deployment.WebParsingDeploymentProcessor.deploy(WebParsingDeploymentProcessor.java:96)
... 9 more
09:57:14,052 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 1) WFLYCTL0013: Operation ("deploy") failed - address: ([("deployment" => "SpringMVC.war")]) - failure description: {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit."SpringMVC.war".PARSE" => "WFLYSRV0153: Failed to process phase PARSE of deployment "SpringMVC.war"
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYUT0027: Failed to parse XML descriptor "/D:/Development_Folder/jboss-eap-7.4/bin/content/SpringMVC.war/WEB-INF/web.xml" at [109,2]
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[109,2]
Message: Unexpected element '{http://java.sun.com/xml/ns/j2ee http://www.springframework.org/schema/security}global-method-security' encountered"}}
09:57:14,054 ERROR [org.jboss.as.server] (management-handler-thread - 1) WFLYSRV0021: Deploy of deployment "SpringMVC.war" was rolled back with the following failure message:
{"WFLYCTL0080: Failed services" => {"jboss.deployment.unit."SpringMVC.war".PARSE" => "WFLYSRV0153: Failed to process phase PARSE of deployment "SpringMVC.war"
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYUT0027: Failed to parse XML descriptor "/D:/Development_Folder/jboss-eap-7.4/bin/content/SpringMVC.war/WEB-INF/web.xml" at [109,2]
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[109,2]
Строка ошибки 109 находится там внутри web.xml
. web.xml
Файл упоминается ниже:-
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Archetype Created Web Application</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.htm;</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
<welcome-file>redirect.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>posturl</param-name>
<param-value>https://www.sandbox.paypal.com/cgi-bin/webscr
</param-value>
</context-param>
<!-- <context-param> <param-name>posturl</param-name> <param-value>https://www.paypal.com/cgi-bin/webscr</param-value>
</context-param> -->
<context-param>
<param-name>SendGridKey</param-name>
<param-value>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
</param-value>
</context-param>
<context-param>
<param-name>cmd</param-name>
<param-value>_xclick</param-value>
</context-param>
<context-param>
<param-name>business</param-name>
<param-value>vidyareddy0591@gmail.com</param-value>
</context-param>
<context-param>
<param-name>password</param-name>
<param-value>S6LEKZG9T9AJ7EHU</param-value>
</context-param>
<context-param>
<param-name>signature</param-name>
<param-value>AiPC9BjkCyDFQXbSkoZcgqH3hpacAWLboo8SO7HpBsWSokvk8HXvlV1J
</param-value>
</context-param>
<context-param>
<param-name>returnurl</param-name>
<param-value>http://localhost:8080/SpringMVC/paypal/success
</param-value>
</context-param>
<context-param>
<param-name>cancelurl</param-name>
<param-value>http://localhost:8080/paypal/cancel</param-value>
</context-param>
<context-param>
<param-name>ApplicationContext</param-name>
<param-value>/WEB-INF/applicationContext.xml
WEB-INF/security-context.xml
</param-value>
</context-param>
<servlet>
<servlet-name>SpringMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SpringMVC</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.request.RequestContextListener
</listener-class>
</listener>
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/SpringMVC/*</url-pattern>
</filter-mapping>
<global-method-security
pre-post-annotations="enabled" />
<!-- <http pattern="/SpringMVC/" security="none"/> -->
<http pattern="*/login/*" security="none" />
<http pattern="*/signup/*" security="none" />
<http pattern="*/SpringMVC/*"
entry-point-ref="restAuthenticationEntryPoint"
create-session="stateless">
<csrf disabled="true" />
<custom-filter before="FORM_LOGIN_FILTER"
ref="jwtAuthenticationFilter" />
</http>
<http auto-config="true">
<intercept-url pattern="/**" access="ROLE_USER" />
<http-basic />
</http>
<beans>
<bean id="jwtAuthenticationFilter"
class="com.security.JwtAuthenticationFilter">
<property name="authenticationManager"
ref="authenticationManager" />
<property name="authenticationSuccessHandler"
ref="jwtAuthenticationSuccessHandler" />
</bean>
</beans>
<authentication-manager
alias="authenticationManager">
<authentication-provider
ref="jwtAuthenticationProvider" />
</authentication-manager>
</web-app>
У меня нет прежнего представления о Spring MVC, так как мне нужно просто развернуть один и тот же проект Spring MVC на моей машине, чтобы вызвать API из кода python.
Пожалуйста, помогите в решении этой проблемы.
Комментарии:
1. Теги из строк 109 и 141 не должны быть частью web.xml, это должно быть частью xml конфигурации spring. ССЫЛКА: docs.spring.io/spring-security/site/docs/current/guides/…
Ответ №1:
Следующие вещи относятся к весенней безопасности, но сейчас вы помещаете их в web.xml
. Они не определены спецификацией сервлета и, следовательно, являются ошибками.
В соответствии с вашей конфигурацией, они должны быть помещены в WEB-INF/security-context.xml
<global-method-security
pre-post-annotations="enabled" />
<!-- <http pattern="/SpringMVC/" security="none"/> -->
<http pattern="*/login/*" security="none" />
<http pattern="*/signup/*" security="none" />
<http pattern="*/SpringMVC/*"
entry-point-ref="restAuthenticationEntryPoint"
create-session="stateless">
<csrf disabled="true" />
<custom-filter before="FORM_LOGIN_FILTER"
ref="jwtAuthenticationFilter" />
</http>
<http auto-config="true">
<intercept-url pattern="/**" access="ROLE_USER" />
<http-basic />
</http>
<beans>
<bean id="jwtAuthenticationFilter"
class="com.security.JwtAuthenticationFilter">
<property name="authenticationManager"
ref="authenticationManager" />
<property name="authenticationSuccessHandler"
ref="jwtAuthenticationSuccessHandler" />
</bean>
</beans>
<authentication-manager
alias="authenticationManager">
<authentication-provider
ref="jwtAuthenticationProvider" />
</authentication-manager>
Комментарии:
1. спасибо за ваше решение. Это означает, что мне нужно поместить вышеуказанные строки в отдельные security-context.xml файл. Каким будет XML — объявление и схема этого файла. Не могли бы вы, пожалуйста, поделиться полным security-context.xml файл с объявлением xml и xsd.
2. Пожалуйста, будьте умны и найдите его самостоятельно, например, на github, как <a rel=»noreferrer noopener nofollow» href=»https://github.com/search?q=» это