私のプロジェクトは、Javaベースのコンフィグレーションに完全に基づいていました。Spring Securityのweb.xmlとJavaベースの設定を正しく定義する方法
うまく動作public class MyWebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext container) throws ServletException {
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.register(WebAppConfiguration.class);
AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(dispatcherContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
、と私はそのようなThymeleafのテンプレートでCSRFトークンを取得することができました:だからではなく、スタンダールのweb.xmlの私はこれを持っていた
<meta name="_csrf" th:content="${_csrf.token}"/>
<meta name="_csrf_header" th:content="${_csrf.headerName}"/>
しかし、今私が展開する必要がありますGoogle App Engineへの私のプロジェクトであり、web.xmlを持っている必要があります。それ以外の場合は起動しません。 私はweb.xmlファイルを追加し、上記のJavaの設定を削除します。
<context-param>
<param-name>contextClass</param-name>
<param-value>
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>com.demshin.medpro.configuration.WebAppConfiguration</param-value>
</context-param>
<servlet>
<servlet-name>springServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
そして、私は私のアプリのURLを開こうとすると、私は例外を取得:
org.thymeleaf.exceptions.TemplateProcessingException:例外 SpringELの式を評価しています: "_csrf.token"
私が思うに、この問題はフィルターチェーンが壊れています。 しかし、私はweb.xmlに以下を追加した場合:代わりに、このJavaの設定の
<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>/*</url-pattern>
</filter-mapping>
:
public class SecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer {
public SecurityWebApplicationInitializer() {
super(WebSecurityConfiguration.class);
}
}
トレースは少し異なるが、問題はまだそこにあります。
これはどのように治すことができますか? Google App Engineでweb.xmlを削除する方法がありますか? ありがとうございます。
このようなものは動作しません。 –