2.5的吗? 好像有篇文章,http://www.ibm.com/developerworks/cn/java/j-lo-spring25-ioc/
使用 Spring 2.5 注释驱动的 IoC 功能
http://www.blogjava.net/beansoft/archive/2007/11/30/164230.html
Spring 2.5 标注开发的简单例子 http://www.ibm.com/developerworks/cn/opensource/os-lightweight3/
轻量级开发的成功秘诀,第 3 部分: Spring 露出水面你找找

解决方案 »

  1.   

    用aspectJ语法,直接指包名、方法名就行啦
      

  2.   


    spring2.5注入支持annotation方式,只需要在配置文件中,写如下内容
    <?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:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
           http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"> <context:component-scan base-package="com.aaa.bbb">
    <!--想用spring管理哪个包下的类,就在这里加进来-->
    <context:include-filter type="aspectj" expression="com.aaa.bbb.service..*"/>
    <context:include-filter type="aspectj" expression="com.aaa.bbb.entity..*"/>
    <!--想不让spring初始化就浏览的类,就在这里滤掉-->
    <context:exclude-filter type="aspectj" expression="com.aaa.bbb.action..*"/>
    </context:component-scan>
    </beans>只加入上述方法还是不行的,还要在类中显示的声明annotatino,比如
    package com.aaa.bbb.service;
    import org.springframework.stereotype.Component;@Component("bean2")
    public class TestBean2 {
    public String getString(){
    return "bean2";
    }
    }
    这样的话就可以
    ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
    bean2 = (TestBean2) ctx.getBean("bean2");以上只是一个简单的开发过程,像楼主说的某一个package下的类全部默认注入,而不用写什么东西,似乎还做不到,详细的还请参看spring2.5中文开发文档