annotatedClasses和component-scan冲突吗

annotatedClasses:配置在sessionFactory下面表示的是,哪些实体需要映射,代码如下:

<bean id="sessionFactory"
		class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
		<property name="dataSource" ref="myDataSource" />
		<property name="annotatedClasses">
			<list>
				<value>com.jk.model.User</value>
				<value>com.jk.model.Shop</value>
			</list>
		</property>
		<property name="hibernateProperties">
			<props>
				<prop key="hibernate.dialect">
					org.hibernate.dialect.MySQLDialect
				</prop>
				<prop key="hibernate.show_sql">true</prop>
				<prop key="hibernate.format_sql">true</prop>
				<prop key="hibernate.hbm2ddl.auto">update</prop>
			</props>
		</property>
	</bean>

  

2.component-scan表示的是扫描哪些包来装配进我们的spring中,以供后面的配置调用,一般要和

<context:annotation-config />一起使用,表示的是启用注解配置。

示例如下:

 <context:annotation-config />
 <context:component-scan base-package="com.jk" />

  

时间: 2024-08-11 01:34:30

annotatedClasses和component-scan冲突吗的相关文章

注解Annotation的IoC:从@Autowired到@Component

注解Annotation的IoC:从@Autowired到@Component 2017-01-20 目录 1 什么是注解2 不使用注解示例  2.1 com.springioc.animal.Monkey  2.2 com.springioc.animal.Tiger  2.3 com.springioc.bean.Zoo  2.4 com.springioc.main.AppMain  2.5 Beans.xml3 使用注解@Autowired示例  3.1对成员变量使用@Autowired

基于Annotation的IOC 初始化

从Spring2.0 以后的版本中,Spring 也引入了基于注解(Annotation)方式的配置,注解(Annotation)是JDK1.5 中引入的一个新特性,用于简化Bean 的配置,可以取代XML 配置文件.开发人员对注解(Annotation)的态度也是萝卜青菜各有所爱,个人认为注解可以大大简化配置,提高开发速度,但也给后期维护增加了难度.目前来说XML 方式发展的相对成熟,方便于统一管理.随着Spring Boot 的兴起,基于注解的开发甚至实现了零配置.但作为个人的习惯而言,还是

SpingMVC 核心技术帮助文档

SpringMVC 框架使用技巧 声明:本篇文档主要是用于参考帮助文档,没有实例,但几乎包含了SpringMVC 4.2版本的所有核心技术 对于觉得篇幅长的文档,建议大家使用快捷键crtl + F,搜索关键字查询较为方便. 欢迎加群JAVA编程交流群 574337670 21.1 Spring Web MVC框架简介 Spring的模型-视图-控制器(MVC)框架是围绕一个 DispatcherServlet 来设计的,这个Servlet会把请求分发给各个处理器,并支持可配置的处理器映射.视图渲

1. spring boot起步之Hello World

1.1 介绍 自从structs2出现上次的漏洞以后,对spring的关注度开始越来越浓. 以前spring开发需要配置一大堆的xml,后台spring加入了annotaion,使得xml配置简化了很多,当然还是有些配置需要使用xml,比如申明component scan等. 前段时间发现了spring开了一个新的model springboot,主要思想是降低spring的入门,使得新手可以以最快的速度让程序在spring框架下跑起来. 那么如何写Hello world呢? Hello之步骤:

Spring MVC注解配置结合Hibernate的入门教程及其代码实例

原文:Spring MVC注解配置结合Hibernate的入门教程及其代码实例 源代码下载地址:http://www.zuidaima.com/share/1787210045197312.htm 1.概述 本文旨在搭建Spring MVC+Hibernate开发框架,通过一个简单的demo讲解Spring MVC的相关配置文件,以及通过注解方式实现简单功能. 开发框架:Spring+Spring MVC+Hibernate(Spring所用的版本为3.0.5). 数据库:MySQL(数据库名称

spring mvc 编写处理带参数的Controller

在上一随笔记录的基础上,现记录编写处理带有参数的Controller. @Controller //这个注解会告知<context:component:scan> 将HomeController自动检测为一个Bean@RequestMapping("/home")  //这是根Urlpublic class HomeController {        private UserService userService;        @Autowired    public

如何用Spring将Service注入到Servlet中

解决方法有两种(推荐使用第二种) 方法一: 直接重写Servlet的Init()方法,代码如下: public void init(ServletConfig servletConfig) throws ServletException { ServletContext servletContext = servletConfig.getServletContext(); WebApplicationContext webApplicationContext = WebApplicationCo

applicationContext.xml和dispatcher-servlet.xml的区别

在SpringMVC项目中我们一般会引入applicationContext.xml和dispatcher-servlet.xml两个配置文件,这两个配置文件具体的区别是什么呢? Spring 官方文档介绍如下: Spring lets you define multiple contexts in a parent-child hierarchy. The applicationContext.xml defines the beans for the "root webapp context

context:component-scan

Scans the classpath for annotated components that will be auto-registered as Spring beans. By default, the Spring-provided @Component, @Repository, @Service, and @Controller stereotypes will be detected. Note: This tag implies the effects of the 'ann

Spring Batch示例: 读取CSV文件并写入MySQL数据库

Spring Batch示例: 读取CSV文件并写入MySQL数据库 GitHub版本: https://github.com/kimmking/SpringBatchReferenceCN/blob/master/01_introduction/Spring_Batch_MySQL.md 原文链接: Reading and writing CVS files with Spring Batch and MySQL 原文作者: Steven Haines - 技术架构师 下载本教程的源代码: S