jtest中 利用spring注入不成功

dztgc123 2014-08-13 08:00:38
Test.java
package com.test.tianhang.junt_test;

import java.util.List;

import org.jtester.module.spring.annotations.SpringBeanByName;
import org.junit.Test;
import org.unitils.spring.annotation.SpringApplicationContext;

@SpringApplicationContext({"spring/spring-context.xml"})
public class mbtest {
@SpringBeanByName
private SwitchConfig swit;
@Test
public void test1(){
System.out.println(":1");
}

}


spring-context.xml 在src/test/resources/spring下
<?xml version="1.0" encoding="GBK"?>
<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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"
default-autowire="byName">
<bean id="switchConfig" class="com.test.datastation.common.constants.SwitchConfig" init-method="init"/>
</beans>

我在输出那行设置了断点,但是swit没有注入成功,,为null。为什么呢?
...全文
97 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
你可以在你的SwitchConfi中增加一个空的构造,断点空构造方法,用于判断是否spring是否加载过,如果进入断点了,说明spring加载过你这个bean---》查看jtest中是否写的不正确;,如果没有进,那么说明spring没有加载--->查看资源文件是否写对,路径是否正确

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧