(1)在主页面或者公共页面中加入:session.setMaxInactiveInterval(600)引数600单位是秒,即在没有10分钟活动后,session将失效。
这里要注意这个session设定的时间是根据伺服器来计算的,而不是客户端。所以如果是在除错程式,应该是修改伺服器端时间来测试,而不是客户端。
(2)也是比较通用的设定session失效时间的方法,就是在专案的web.xml中设定
<!-- 设定session失效,单位分 -->
<session-config>
<session-timeout>1</session-timeout>
</session-config>
设定为0,-1 表示永不超时
(3)直接在应用伺服器中设定,如果是tomcat,可以在tomcat目录下conf/web.xml中找到元素,tomcat预设设定是30分钟,只要修改这个值就可以了。
<!-- ==================== Default Session Configuration ================= -->
<!-- You can set the default session timeout (in minutes) for all newly -->
<!-- created sessions by modifying the value below. -->
<session-config>
<session-timeout>30</session-timeout>
</session-config>
需要注意的是如果上述三个地方如果都设定了,有个优先顺序的问题,从高到低:(1)>(2)>(3)
session 的timeout不在spring的配置档案里配置,它的配置实在web.xml档案里面
例如像这样
<session-config> <session-timeout>20</session-timeout></session-config>
如何使用纯java config来配置spring mvc
这个不是一定的,随你自己的意思,你可以放在WEB-INF里,也可以放在classpath下。只需在配置web.xml时指定位置即可。
<listener>
<listener-class>
.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:beans.xml
</param-value>
</context-param>
上面就是web.xml中对spring容器的初始化配置,<context-param>中<param-value>中的classpath:beans.xml 即是spring配置档案beans.xml的位置(classpath下,在myeclipse的工程中是src目录下)
这个不是一定的,随你自己的意思,你可以放在WEB-INF里,也可以放在classpath下。只需在配置web.xml时指定位置即可。
.springframework.web.context.ContextLoaderListener
contextConfigLocation
classpath:beans.xml
上面就是web.xml中对spring容器的初始化配置,中中的classpath:beans.xml 即是spring配置档案beans.xml的位置(classpath下,在myeclipse的工程中是src目录下)
spring mvc应用基于Java config配置是怎么启动的
<!-- 包扫描 -->
<context:ponent-scan base-package=".eduask.chp.controller"></context:ponent-scan>
<context:annotation-config>
<!--检视解析器 -->
<bean
class=".springframework.web.servlet.view.InternalResourceViewResolver">
<property name=prefix value="/view/"></property>
<property name=suffix value=".jsp"></property>
</bean>
<mvc:annotation-driven></mvc:annotation-driven>
转: https://blog.csdn.net/HaHa_Sir/article/details/79105951
1、用法示例: 在spring.xml配置文件中添加标签
2、在 spring.xml 中使用配置文件属性:
3、在java文件中使用:
需开启注解注入:
<context:annotation-config/>或 <context:component-scan/>
1、用法示例: 在spring.xml配置文件中添加标签
2、在spring.xml 中使用配置文件属性:
3、在java文件中使用:
1、用法示例:在java类文件中使用 PropertySource 注解:
2、在java文件中使用:
1、用法示例:在 spring.xml 中使用 <bean>标签进行配置
2、 PropertyPlaceholderConfigurer 配置方法,等价于 方式一,用法参考方法一
五、 还可以使用 org.springframework.beans.factory.config.PropertiesFactoryBean 加载,这里不再逐一列举了。
清楚你说的java类配置指的是什么。但是要配置和spring mvc 集成的项目可以用一下的方式。spring mvc 本身是面向web项目的,一般需要在容器中运行。
1,java web项目如果要集成spring mvc需要在web容器中例如tomcat的web.xml 配置 spring的启动监听器和请求控制器2大核心类。
<listener><description>spring</description>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<description>spring mvc servlet</description>
<servlet-name>springMVC</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>springMVC</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
在servlet3.0 中增加了@WebListener等系列0配置的方式。这里和spring没有关系。
2,如果要测试spring可以使用main方法或者@test.
public static void main(String[] args) {ClassPathXmlApplicationContext ap = new ClassPathXmlApplicationContext("application-spring.xml")
UserService userService = (UserService) ap.getBean("userService")
}