`
TRAMP_ZZY
  • 浏览: 141582 次
社区版块
存档分类
最新评论

Maven eclipse 构建Spring 项目配置文件

 
阅读更多
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:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	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
	http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">
	
	<!-- Root Context: defines shared resources visible to all other web components -->
	
	<context:component-scan base-package="com.baobaotao.dao" />
	<context:component-scan base-package="com.baobaotao.service" />
	<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
		<property name="driverClassName" value="com.mysql.jdbc.Driver" />
		<property name="url" value="jdbc:mysql://localhost:3306/sampledb" />
		<property name="username" value="root" />
		<property name="password" value="root" />
	</bean>
	<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
		<property name="dataSource">
			<ref bean="dataSource"/>
		</property>
	</bean>
	<!-- 配置事务 -->
	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource">
			<ref bean="dataSource"/>
		</property>
	</bean>
	<aop:config proxy-target-class="true">
		<aop:pointcut expression="execution(* com.baobaotao.service..*(..))" id="serviceMethod"/>
		<aop:advisor pointcut-ref="serviceMethod" advice-ref="txAdvice"/>
	</aop:config>
	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="*"/>
		</tx:attributes>
	</tx:advice>
</beans>


--------------------------------------------------------------------------------
xxx-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:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
     xmlns:util="http://www.springframework.org/schema/util"
     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/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd              
                         http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd">
	<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
	
	<!-- Enables the Spring MVC @Controller programming model -->
	<mvc:annotation-driven />
	
	<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
	<mvc:resources mapping="/resources/**" location="/resources/" />

	<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
	<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
		<property name="prefix" value="/WEB-INF/views/" />
		<property name="suffix" value=".jsp" />
	</bean>
	<context:component-scan base-package="com.bjfu.chapterone" />
	<context:component-scan base-package="com.baobaotao.web" />
</beans>


web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

	<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>/WEB-INF/spring/applicationContext.xml</param-value>
	</context-param>
	
	<!-- Creates the Spring Container shared by all Servlets and Filters -->
	<listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>

	<!-- Processes application requests -->
	<servlet>
		<servlet-name>appServlet</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
	</servlet>
		
	<servlet-mapping>
		<servlet-name>appServlet</servlet-name>
		<url-pattern>/</url-pattern>
	</servlet-mapping>

</web-app>


----------------------------------------------------------------------------------
log4j.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration PUBLIC "-//APACHE//DTD LOG4J 1.2//EN" "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

	<!-- Appenders -->
	<appender name="console" class="org.apache.log4j.ConsoleAppender">
		<param name="Target" value="System.out" />
		<layout class="org.apache.log4j.PatternLayout">
			<param name="ConversionPattern" value="%-5p: %c - %m%n" />
		</layout>
	</appender>
	
	<!-- Application Loggers -->
	<logger name="com.bjfu.chapterone">
		<level value="info" />
	</logger>
	
	<!-- 3rdparty Loggers -->
	<logger name="org.springframework.core">
		<level value="info" />
	</logger>
	
	<logger name="org.springframework.beans">
		<level value="info" />
	</logger>
	
	<logger name="org.springframework.context">
		<level value="info" />
	</logger>

	<logger name="org.springframework.web">
		<level value="info" />
	</logger>

	<!-- Root Logger -->
	<root>
		<priority value="info" />
		<appender-ref ref="console" />
	</root>
	
</log4j:configuration>

分享到:
评论

相关推荐

    java教程之手把手教你用eclipse新建基于maven构建的spring boot项目.zip

    在【标签】中提到了Java、Eclipse、Maven和Spring Boot,这些都是构建Spring Boot应用的核心组件。 1. **JDK下载安装**: - 对于Windows用户,可以从Oracle官方网站下载适用于各自操作系统的JDK安装包,按照向导...

    使用Eclipse构建Maven的Spring MVC项目的源代码

    本文将详细解析如何使用Eclipse构建一个基于Maven的Spring MVC项目,并探讨相关知识点。 首先,Maven是一个强大的项目管理和构建工具,它通过依赖管理和项目信息管理,使得开发者可以更高效地构建项目。Maven使用一...

    构建为eclipse项目的spring源码

    在Eclipse中构建Spring源码项目,可以帮助我们深入理解Spring的工作原理,从而更好地利用它来构建高效、可维护的Java应用。以下将详细阐述如何构建和探索Spring源码。 1. **获取源码** Spring源码可以从官方GitHub...

    Eclipse使用Maven构建web项目视频教程

    本教程提供的"用maven新建web项目.exe"可能是一个辅助工具,用于指导用户手动执行上述步骤,而"使用Eclipse构建web项目.txt"可能包含了详细的文字说明或步骤。通过学习这些资料,开发者可以掌握使用Eclipse和Maven...

    Maven+eclipse构建Web项目

    本文将详细探讨如何利用Maven和Eclipse构建Web项目,尤其是以SpringMVC项目为例,深入讲解从项目创建到配置的全过程。 #### 一、创建Maven项目 创建Maven项目的第一步是在Eclipse中选择“File” -&gt; “New” -&gt; ...

    使用Eclipse构建Maven的SpringMVC项目

    6. **创建Spring配置文件**:在WEB-INF下创建spring-mvc-config.xml,配置Spring MVC的bean。例如: ```xml &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi=...

    在eclipse中配置maven,新建springboot项目.zip

    然后在`User Settings`选项卡下,配置`User settings file`为Maven的用户配置文件`conf/settings.xml`。 4. **设置Maven镜像**:修改`settings.xml`文件,配置`mirrors`节点,设置国内的Maven镜像源,这样可以加快...

    Eclipse+tomcat+maven 配置Spring mvc图文教程.zip

    4. 创建Spring配置文件,定义Controller Bean和其他相关Bean。 5. 编写Controller类,实现业务逻辑。 6. 创建视图模板(JSP、Thymeleaf等),并配置视图解析器。 7. 在Eclipse中配置Tomcat服务器,将项目部署上去。 ...

    用Maven搭建Spring+Spring MVC+Hibernate框架

    本篇文章将深入探讨如何使用Maven作为构建工具,在Eclipse环境中搭建一个整合了Spring、Spring MVC和Hibernate的项目。 首先,让我们了解Maven。Maven是Apache开发的一款项目管理和综合工具,它通过一个项目对象...

    Eclipse+tomcat+maven 配置Spring mvc图文教程

    本教程将详细介绍如何在Eclipse IDE中配置开发环境,包括Eclipse、Tomcat服务器、Maven构建工具以及Spring MVC的配置。以下是详细步骤: 1. **基础环境配置** - **JDK安装**:首先,你需要安装Java Development ...

    一个入门的spring mvc demo,基于eclipse maven

    通过学习和实践这个demo,你可以理解Spring MVC的基本工作原理,掌握如何创建Controller、配置DispatcherServlet、处理请求和响应,以及如何利用Maven管理项目构建。这将为你进一步深入Spring框架和Java Web开发打下...

    Eclipse Spring Boot maven web demo 简单项目实例

    【Eclipse Spring Boot Maven Web Demo 简单项目实例】是一个实用的学习资源,旨在帮助开发者快速搭建基于Spring Boot、Maven和Eclipse的Web应用程序。这个项目实例为初学者提供了良好的起点,让他们能够理解并实践...

    Eclipse搭建SpringCloud.zip

    Spring Cloud是一款备受推崇的微服务框架,它为开发者提供了在分布式系统(如配置管理、服务发现、断路器、智能路由、微代理、控制总线、一次性令牌、全局锁、领导选举、分布式会话、集群状态)中快速构建一些常见...

    使用Eclipse构建Maven的Web项目.docx

    使用 Eclipse 构建 Maven 的 Web 项目 在本文中,我们将详细介绍如何使用 Eclipse 构建 Maven 的 Web 项目。首先,我们需要了解 Maven 的基本概念和 Eclipse 的 Maven 插件的使用。 一、直接建立 Maven 项目 ...

    使用Eclipse构建Maven的Web项目用jetty启动.docx

    使用Eclipse构建Maven的Web项目用jetty启动 本文主要介绍了使用Eclipse构建Maven的Web项目,并使用jetty启动的步骤。下面是相关知识点的总结: 1. 使用Eclipse构建Maven项目 在Eclipse中构建Maven项目需要选择 ...

    eclipse通过Maven创建一个Spring MVC项目

    步骤8:创建servlet-context.xml文件(位于src/main/webapp/WEB-INF/spring/appServlet/),这是Spring MVC的核心配置文件。配置处理器映射器、视图解析器和其他组件: ```xml &lt;beans xmlns="http://www.spring...

Global site tag (gtag.js) - Google Analytics