Java spring/maven项目中静态文件(css和js)的位置
我正在尝试在我当前的spring(不是spring boot)项目中的ThymileAF视图中引用css和js文件,如下所示:Java spring/maven项目中静态文件(css和js)的位置,java,spring,maven,spring-mvc,Java,Spring,Maven,Spring Mvc,我正在尝试在我当前的spring(不是spring boot)项目中的ThymileAF视图中引用css和js文件,如下所示: <link rel="stylesheet" th:href="@{/css/style.css}"/> springmvcapp servlet.xml <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun
<link rel="stylesheet" th:href="@{/css/style.css}"/>
springmvcapp servlet.xml
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>loja</display-name>
<servlet>
<servlet-name>springmvcapp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>springmvcapp</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="org.kleber"></context:component-scan>
<bean id="templateResolver" class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
<property name="prefix">
<value>/WEB-INF/views/</value></property>
<property name="suffix">
<value>.html</value></property>
<property name="templateMode">
<value>HTML5</value></property></bean>
<bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
<property name="templateResolver" ref="templateResolver"></property></bean>
<bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
<property name="templateEngine" ref="templateEngine"></property></bean>
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="messages"></property></bean>
</beans>
<web-app>
<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>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
/WEB-INF/views/
.html
HTML5
applicationContext.xml
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>loja</display-name>
<servlet>
<servlet-name>springmvcapp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>springmvcapp</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan base-package="org.kleber"></context:component-scan>
<bean id="templateResolver" class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
<property name="prefix">
<value>/WEB-INF/views/</value></property>
<property name="suffix">
<value>.html</value></property>
<property name="templateMode">
<value>HTML5</value></property></bean>
<bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
<property name="templateResolver" ref="templateResolver"></property></bean>
<bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
<property name="templateEngine" ref="templateEngine"></property></bean>
<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basename" value="messages"></property></bean>
</beans>
<web-app>
<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>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
springSecurityFilterChainorg.springframework.web.filter.DelegatingFilterProxy
springSecurityFilterChain
/*
org.springframework.web.context.ContextLoaderListener
将
和
添加到springmvcapp servlet.xml
@manish我添加了这个,现在当我尝试在浏览器中访问webapp时,我得到了404页。除了添加的两行之外,上面显示的文件中没有其他更改。请查看Github上的可用内容,然后与应用程序进行比较,以了解出现错误的原因。@manish我注意到您的示例项目中没有*-servlet.xml
文件,所有bean和资源都在上下文xml文件springWebContext,xml
中声明。你能告诉我你为什么用这种方法吗?我正在使用*-servlet.xml
文件进行声明?这两种方法的区别是什么?springWebContext.xml
是web上下文加载程序文件(您称之为*-servlet.xml
),因此方法没有区别。示例应用程序中使用的命名约定仅基于层名称(springDataContext.xml
,springServiceContext.xml
,springWebContext.xml
,等等)。将
和
添加到springmvcapp servlet.xml
@manish我添加了这个,现在当我尝试在浏览器中访问webapp时,我得到了404页。除了添加的两行之外,上面显示的文件中没有其他更改。请查看Github上的可用内容,然后与应用程序进行比较,以了解出现错误的原因。@manish我注意到您的示例项目中没有*-servlet.xml
文件,所有bean和资源都在上下文xml文件springWebContext,xml
中声明。你能告诉我你为什么用这种方法吗?我正在使用*-servlet.xml
文件进行声明?这两种方法的区别是什么?springWebContext.xml
是web上下文加载程序文件(您称之为*-servlet.xml
),因此方法没有区别。示例应用中使用的命名约定仅基于层名称(springDataContext.xml
、springServiceContext.xml
、springWebContext.xml
等)。