`
huanglz19871030
  • 浏览: 248708 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

spring注解配置文件解析

阅读更多

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>

0
4
分享到:
评论

相关推荐

    Spring 自定义注解的解析

    在Spring配置类或者XML配置文件中,使用`@ComponentScan`并添加`@ComponentScan annonation`属性,指定自定义注解的名称。这样,Spring在扫描过程中会识别并处理标记了这个注解的类。 ```java import org.spring...

    spring注解方式解析

    注解方式的自动装配使得开发者无需在XML配置文件中声明bean之间的依赖关系,只需在类上使用@Autowired注解即可。例如: ```java @Service public class UserService { @Autowired private UserRepository ...

    spring注解aop配置详解

    Spring AOP,即Aspect-Oriented Programming(面向切面编程),是Spring框架的重要特性,它为应用程序提供了声明式的企业级服务,如...在实际开发中,熟练掌握Spring AOP的注解配置无疑会极大地提升我们的工作效率。

    Spring读取配置文件原理(Spring如何依赖注入的)

    总的来说,Spring通过读取配置文件(XML或注解形式),解析并生成BeanDefinition,然后根据BeanDefinition实例化bean并进行依赖注入,从而实现了对象的管理。理解这一过程有助于我们更好地设计和使用Spring框架,...

    Spring注解注入属性

    使用Spring注解进行依赖注入,如`@Autowired`和`@Resource`,不仅简化了代码结构,减少了XML配置文件的冗余,还增强了代码的可读性和灵活性。通过合理利用这些注解及其辅助注解如`@Qualifier`,开发者可以更高效地...

    Spring3.0 配置文件中加载Properties文件的小例子

    接下来,我们将在Spring的配置文件(如`applicationContext.xml`)中声明一个`PropertyPlaceholderConfigurer` bean,它负责加载并解析Properties文件。配置如下: ```xml class="org.springframework.beans....

    对Spring中注解怎么实现的一些基本原理

    本文将深入探讨Spring注解的基本原理,包括它们如何被解析、处理以及如何影响应用程序的生命周期。 首先,我们需要了解注解在Java语言中的本质。注解是一种元数据,允许程序员在源代码中嵌入信息,这些信息可以被...

    Spring依赖包和配置文件

    在Spring开发中,依赖包和配置文件是构建应用程序的基础。本篇将详细介绍Spring依赖包和配置文件的相关知识。 一、Spring依赖包 1. **Spring Core**:这是Spring框架的核心部分,提供了IoC(Inversion of Control,...

    spring配置文件详细介绍

    Spring容器(ApplicationContext)会解析这些配置文件,创建并管理对象实例。 在Spring配置文件中,最重要的元素是`&lt;bean&gt;`。`&lt;bean&gt;`元素定义了一个Spring管理的对象,也称为bean。它包含几个关键属性,如`id`...

    Spring demo 自动检测注解

    通常,这样的示例会包含一个或多个使用`@Autowired`注解的类,以及相关的配置文件或Java配置类。通过分析这个示例,我们可以更好地理解Spring自动检测注解的实际应用。 总结来说,Spring的自动检测注解`@Autowired`...

    spring3.1相关配置文件

    在这个压缩包中,我们很可能会找到与Spring 3.1配置相关的各种文件,如XML配置文件、Java配置类以及相关文档。 1. **Spring核心**:Spring的核心特性包括依赖注入(Dependency Injection,DI)和面向切面编程...

    Spring源码分析:配置文件读取流程 - ImportNew

    #### 配置文件解析过程 配置文件的解析主要由`BeanDefinitionReader`完成,它可以是`XmlBeanDefinitionReader`或`AnnotationBeanDefinitionReader`,具体取决于配置方式。例如,在XML配置文件的情况下,`...

    SPring注解及页面跳转实例

    在实际开发中,我们往往需要更加灵活地配置Spring MVC的应用配置文件位置。下面介绍如何自定义这些配置。 1. **修改`web.xml`**: - 在`web.xml`中使用`&lt;init-param&gt;`来指定配置文件的位置,可以是多个文件或模式...

    spring中的BeanFactory解析xml文件

    当我们谈论“Spring中的BeanFactory解析XML文件”时,我们实际上是在讨论如何通过XML配置文件来定义、创建和管理bean。这篇文章将深入探讨BeanFactory的工作原理,以及XML配置文件在其中的作用。 首先,BeanFactory...

    spring注解实例

    在Spring框架中,注解提供了元数据的方式来配置bean,使得我们不再需要XML配置文件。常见的注解包括@Component、@Service、@Repository和@Controller,它们用于声明组件,分别对应通用、服务、数据访问和Web层。此外...

    spring读取jar中的配置文件

    在处理JAR内的配置文件时,通常会使用`@PropertySource`注解来指示Spring从特定资源加载属性。例如: ```java @Configuration @PropertySource("classpath:/config/application.properties") public class ...

    详解spring注解配置启动过程

    以下是对Spring注解配置启动过程的详细解析: 1. **初始化起点**: - 在Spring Web应用中,启动过程通常始于一个继承自`AbstractAnnotationConfigDispatcherServletInitializer`的类。例如,`WebMvcInit` 类中,...

    BlazeDS+Spring+SpringMVC 注解方式配置文件

    3. `springmvc-config.xml`:SpringMVC的配置文件,定义处理器映射器、视图解析器等。 4. `flex-servlet.xml`:BlazeDS的配置文件,用于配置消息经纪人和服务。 通过以上配置,我们可以创建一个高效的Java Web应用...

    Spring动态加载配置文件

    要实现动态加载配置文件,我们可以利用Spring的`PropertyPlaceholderConfigurer`或`@PropertySource`注解。`PropertyPlaceholderConfigurer`是Spring早期版本中处理属性文件的工具,而`@PropertySource`则是从Spring...

    springmvc + spring + mybatis + maven整合配置文件

    1. **Mapper接口**:定义数据库操作的方法,与XML配置文件或注解对应。 2. **SQL映射文件**:编写具体的SQL语句,可以动态化处理,支持复杂的查询需求。 3. **MyBatis-Spring整合**:使MyBatis与Spring无缝集成,...

Global site tag (gtag.js) - Google Analytics