- 浏览: 248708 次
- 性别:
- 来自: 深圳
-
文章分类
最新评论
-
sweed0:
为何每一段代码都重复一次呢?
spring注解实例二 -
Gary_Huangpf:
- - 插件报错啊
Ext前台分页 -
ddvk2007:
版主 我想請問你所說的mapreduce是hadoop的還是g ...
MapReduce中的Shuffle和Sort分析 -
人可木:
好问章,楼主写的相当详细。。。多谢。。。
findbugs插件的安装与应用 -
hautbbs:
按照博主的方法启动调试出现jvm terminated.Ex ...
10分钟学会使用MyEclipse断点调试js
1、applicationContext.xml
<?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:tx="http://www.springframework.org/schema/tx"
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
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
<description>数据访问的配置文件</description>
<!-- 导入配置文件 -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:config.xml</value>
</list>
</property>
</bean>
<!-- 激活在bean中定义的各种注解,@Transactional注解除外,它需要tx:annotation-driven激活 -->
<context:annotation-config/>
<!-- 使用annotation 自动注册bean,并保证@Required,@Autowired的属性被注入 -->
<context:component-scan base-package="com.ztev.fipmis" />
<context:component-scan base-package="com.ztev.webapp" />
<!-- 数据源配置 -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
<!-- 以下设置解决connection reset问题 -->
<property name="testOnBorrow" value="true" />
<property name="testWhileIdle" value="true" />
<property name="validationQuery" value="select 1" />
</bean>
<!-- 分页实例 -->
<bean id="pagination" class="com.ztev.pagination.impl.PageSqlServer">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 数据库的事务管理器配置 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 使用annotation定义数据库事务,这样可以在类或方法中直接使用@Transactional注解来声明事务 -->
<tx:annotation-driven transaction-manager="transactionManager" />
</beans>
2、fipmis-servlet.xml
<?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">
<description>与web相关的配置</description>
<!-- 显示层采用JSTL -->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/pages/" />
<property name="suffix" value=".jsp" />
</bean>
<!--
启动Spring MVC的注解功能,完成请求和注解POJO的映射,也可由<context:annotation-config/>启动
<bean
class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"/>
-->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="30000000" />
</bean>
<!-- 登陆拦截器 -->
<bean id="loginInterceptor" class="com.ztev.webapp.LoginInterceptor">
<property name="loginView" value="/index.jsp"/>
</bean>
<bean id="urlMappingManualLogin" autowire="no"
class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
<property name="interceptors">
<list>
<ref bean="loginInterceptor" />
</list>
</property>
</bean>
</beans>
3、config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>系统配置</comment>
<!-- 数据库相关配置 ====================================================================================== -->
<!-- 数据库配置 -->
<entry key="jdbc.driverClassName">net.sourceforge.jtds.jdbc.Driver</entry>
<entry key="jdbc.url">jdbc:jtds:sqlserver://127.0.0.1:1433/fipmis;charset=gbk</entry>
<entry key="jdbc.username">sa</entry>
<entry key="jdbc.password">123456</entry>
<!-- 地图服务相关的配置 -->
<entry key="map.server.host">127.0.0.1</entry><!-- 地图主机地址,如果为空则视为和web服务在同一台服务器上 -->
<entry key="map.server.port"></entry><!-- 地图服务端口,如果为空则视为web默认端口,即80 -->
<entry key="map.server.path">fipmismap</entry><!-- 地图服务路径,即IIS中发布的虚拟目录名称 -->
<!-- 上传目录及权限限制 -->
<entry key="file.base.uri">/uploads/file</entry>
<entry key="files.denied">jsp,vm,cgi,dll,asp,php,aspx,pl,exe</entry>
</properties>
发表评论
-
spring AOP
2012-06-13 11:14 928先简单的说说spring aop使用的好处:利用AOP横向添加 ... -
spring IOC的使用
2012-06-13 10:58 969Ioc和他的作用,简单的来讲,就是由容器控制程序之间的关 ... -
spring IOC介绍
2012-06-13 10:55 1366首先想说说IoC(Inversion of ... -
spring概述
2012-06-13 10:52 817随着越来越多的项目 ... -
spring学习总结
2010-02-04 08:49 978先说说简单地使用Struts2做Web时的经历: 1.经常需要 ... -
spring注解实例二
2010-01-26 11:22 2384昨天对Spring注解有了一个整体认识,至少完成了一个简单的w ... -
spring注解实例一
2010-01-26 11:15 2951先来构建一个极为简单的web应用,从controller到da ... -
使用 Spring 2.5 基于注解驱动的 Spring MVC(二)
2010-01-22 11:13 3439我们在 ② 处添加了一个 ModelMap 属性,其属性名为 ... -
使用 Spring 2.5 基于注解驱动的 Spring MVC(一)
2010-01-22 11:05 1375基于注解的配置有越来越流行的趋势,Spring 2.5 顺应这 ... -
spring注解详解
2010-01-22 09:57 13581.准备工作(1)导入common-annotations.j ... -
spring注解
2010-01-13 09:56 1032Spring JSR-250注解 注释配 ... -
spring相关配置内容解析
2010-01-05 14:27 13351、web.xml配置文件: <? ... -
Spring MVC 配置【转】
2010-01-03 14:51 1073一,配置分发器 Dispatche ... -
spring mvc 学习笔记
2010-01-03 14:41 1168一、与struts的不同 1.Spr ... -
Spring Mvc快速入门
2010-01-03 14:20 1756Spring MVC是结构最清晰的MVC ... -
Spring 可代码简化操作类
2009-12-28 09:31 1069SimpleJdbcTemplate类是Jd ... -
Spring 命名参数操作类NamedParameterJdbcTemplate
2009-12-28 09:28 1813在传统的SQL语句中,参数都是用'?'占 ... -
Spring JdbcTemplate操作类
2009-12-24 10:42 27991.JdbcTemplate ...
相关推荐
在Spring配置类或者XML配置文件中,使用`@ComponentScan`并添加`@ComponentScan annonation`属性,指定自定义注解的名称。这样,Spring在扫描过程中会识别并处理标记了这个注解的类。 ```java import org.spring...
注解方式的自动装配使得开发者无需在XML配置文件中声明bean之间的依赖关系,只需在类上使用@Autowired注解即可。例如: ```java @Service public class UserService { @Autowired private UserRepository ...
Spring AOP,即Aspect-Oriented Programming(面向切面编程),是Spring框架的重要特性,它为应用程序提供了声明式的企业级服务,如...在实际开发中,熟练掌握Spring AOP的注解配置无疑会极大地提升我们的工作效率。
总的来说,Spring通过读取配置文件(XML或注解形式),解析并生成BeanDefinition,然后根据BeanDefinition实例化bean并进行依赖注入,从而实现了对象的管理。理解这一过程有助于我们更好地设计和使用Spring框架,...
使用Spring注解进行依赖注入,如`@Autowired`和`@Resource`,不仅简化了代码结构,减少了XML配置文件的冗余,还增强了代码的可读性和灵活性。通过合理利用这些注解及其辅助注解如`@Qualifier`,开发者可以更高效地...
接下来,我们将在Spring的配置文件(如`applicationContext.xml`)中声明一个`PropertyPlaceholderConfigurer` bean,它负责加载并解析Properties文件。配置如下: ```xml class="org.springframework.beans....
本文将深入探讨Spring注解的基本原理,包括它们如何被解析、处理以及如何影响应用程序的生命周期。 首先,我们需要了解注解在Java语言中的本质。注解是一种元数据,允许程序员在源代码中嵌入信息,这些信息可以被...
在Spring开发中,依赖包和配置文件是构建应用程序的基础。本篇将详细介绍Spring依赖包和配置文件的相关知识。 一、Spring依赖包 1. **Spring Core**:这是Spring框架的核心部分,提供了IoC(Inversion of Control,...
Spring容器(ApplicationContext)会解析这些配置文件,创建并管理对象实例。 在Spring配置文件中,最重要的元素是`<bean>`。`<bean>`元素定义了一个Spring管理的对象,也称为bean。它包含几个关键属性,如`id`...
通常,这样的示例会包含一个或多个使用`@Autowired`注解的类,以及相关的配置文件或Java配置类。通过分析这个示例,我们可以更好地理解Spring自动检测注解的实际应用。 总结来说,Spring的自动检测注解`@Autowired`...
在这个压缩包中,我们很可能会找到与Spring 3.1配置相关的各种文件,如XML配置文件、Java配置类以及相关文档。 1. **Spring核心**:Spring的核心特性包括依赖注入(Dependency Injection,DI)和面向切面编程...
#### 配置文件解析过程 配置文件的解析主要由`BeanDefinitionReader`完成,它可以是`XmlBeanDefinitionReader`或`AnnotationBeanDefinitionReader`,具体取决于配置方式。例如,在XML配置文件的情况下,`...
在实际开发中,我们往往需要更加灵活地配置Spring MVC的应用配置文件位置。下面介绍如何自定义这些配置。 1. **修改`web.xml`**: - 在`web.xml`中使用`<init-param>`来指定配置文件的位置,可以是多个文件或模式...
当我们谈论“Spring中的BeanFactory解析XML文件”时,我们实际上是在讨论如何通过XML配置文件来定义、创建和管理bean。这篇文章将深入探讨BeanFactory的工作原理,以及XML配置文件在其中的作用。 首先,BeanFactory...
在Spring框架中,注解提供了元数据的方式来配置bean,使得我们不再需要XML配置文件。常见的注解包括@Component、@Service、@Repository和@Controller,它们用于声明组件,分别对应通用、服务、数据访问和Web层。此外...
在处理JAR内的配置文件时,通常会使用`@PropertySource`注解来指示Spring从特定资源加载属性。例如: ```java @Configuration @PropertySource("classpath:/config/application.properties") public class ...
以下是对Spring注解配置启动过程的详细解析: 1. **初始化起点**: - 在Spring Web应用中,启动过程通常始于一个继承自`AbstractAnnotationConfigDispatcherServletInitializer`的类。例如,`WebMvcInit` 类中,...
3. `springmvc-config.xml`:SpringMVC的配置文件,定义处理器映射器、视图解析器等。 4. `flex-servlet.xml`:BlazeDS的配置文件,用于配置消息经纪人和服务。 通过以上配置,我们可以创建一个高效的Java Web应用...
要实现动态加载配置文件,我们可以利用Spring的`PropertyPlaceholderConfigurer`或`@PropertySource`注解。`PropertyPlaceholderConfigurer`是Spring早期版本中处理属性文件的工具,而`@PropertySource`则是从Spring...
1. **Mapper接口**:定义数据库操作的方法,与XML配置文件或注解对应。 2. **SQL映射文件**:编写具体的SQL语句,可以动态化处理,支持复杂的查询需求。 3. **MyBatis-Spring整合**:使MyBatis与Spring无缝集成,...