美文网首页
spring3.0 遇到的小坑

spring3.0 遇到的小坑

作者: 我弟是个程序员 | 来源:发表于2017-07-06 13:52 被阅读0次

    首先感谢开源的世界,让我们有更多的学习上升空间。本人学习spring的资料来自spring教程。但是按照上面的讲解来实现时,会遇到一些问题。并不是因为教程写错了,而是我确实是这个方面的小白,所以除了spring jar包本身以外,一些基本依赖没有导入,所以才会遇到了所谓的小坑。

    下面首先说一个问题,我到网上下载了所有的spring3.0依赖,然后按照步骤来实现 依赖注入如下:

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
    
        <bean id="myhello" class="com.sanxin.org.HelloWorld">
            <property name="name" value="zhangsan" />
        </bean>
    
    </beans>
    
    ApplicationContext context = new ClassPathXmlApplicationContext(
                    new String[] {"/config/applicationContext.xml","/config/io.xml"}); 
    

    我的配置文件都是没有问题,但是,就是会跑错。
    原因是没有导入其他的包依赖(用来打印日志的包):commons-logging-1.2.jar。作为新手,确实折腾了一会儿,不过还好我会百度大法,所以这并没有难到我。

    下面还要说一个问题,除了xml文件的方式依赖注入外,还有代码的依赖注入如下:

    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    
    @Configuration
    public class AppConfig {    
        @Bean(name="helloBean")
        public HelloWorld helloWorld() {
            return new HelloWorldImpl();
        }   
    }
    
    
     ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);
     HelloWorld obj = (HelloWorld) context.getBean("helloBean");
    

    没错,到这一步,我又走不通了,因为,又抛错提示缺少一个包:cglib-nodep-2.2.2.jar。值得注意的是,本人按照提示,刚才下载了cglib-3.2.5.jar,是不是很像,不过这个包没有解决我的bug。

    好了,目前就遇到这两处小坑,后续遇到了小坑,再慢慢总结,谢谢观看~~~

    相关文章

      网友评论

          本文标题:spring3.0 遇到的小坑

          本文链接:https://www.haomeiwen.com/subject/jwehhxtx.html