Tag: autowired

注入自动连接依赖失败;

我正在开发一个小的Java EE Hibernate Spring应用程序,并出现一个错误: Error creating bean with name 'articleControleur': Injection of autowired dependencies failed; oct. 26, 2011 3:51:44 PM org.apache.catalina.core.ApplicationContext log Grave: StandardWrapper.Throwable org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'articleControleur': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: com.bd.service.ArticleService com.bd.controleur.ArticleControleur.articleService; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type […]

如何在Spring中自动assemblygenerics<T>的bean?

我有一个需要在@Configuration类中自动assembly的bean Item<T> 。 @Configuration public class AppConfig { @Bean public Item<String> stringItem() { return new StringItem(); } @Bean public Item<Integer> integerItem() { return new IntegerItem(); } } 但是当我尝试@Autowire Item<String> ,我得到以下exception。 "No qualifying bean of type [Item] is defined: expected single matching bean but found 2: stringItem, integerItem" 我应该怎么AutowiregenericstypesItem<T>在spring?

如何在Mockito中模拟Spring中的自动assembly的@Value字段?

我使用Spring 3.1.4.RELEASE和Mockito 1.9.5。 在我的Spring类中,我有: @Value("#{myProps['default.url']}") private String defaultUrl; @Value("#{myProps['default.password']}") private String defaultrPassword; // … 从我目前设置的JUnittesting中, @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration({ "classpath:test-context.xml" }) public class MyTest { 我想为我的“defaultUrl”字段嘲笑一个值。 请注意,我不想模拟其他字段的值 – 我想保留它们,只有“defaultUrl”字段。 另外请注意,在我的类中没有明确的“setter”方法(例如setDefaultUrl ),我不想为了testing目的而创build任何方法。 鉴于此,我怎样才能嘲笑这个领域的价值呢?

将bean注入枚举

我有DataPrepareService为报表准备数据,我有一个Enum与报表types,我需要注入到Enum的ReportService或从枚举访问ReportService。 我的服务: @Service public class DataPrepareService { // my service } 我的枚举: public enum ReportType { REPORT_1("name", "filename"), REPORT_2("name", "filename"), REPORT_3("name", "filename") public abstract Map<String, Object> getSpecificParams(); public Map<String, Object> getCommonParams(){ // some code that requires service } } 我试图使用 @Autowired DataPrepareService dataPrepareService; ,但它没有工作 我怎样才能把我的服务注入枚举?

使用注释自动assemblyspring bean

在Springs最新版本中,我们可以使用@Autowired标注自动装载一个bean。 这将使用它的types(或构造函数,如果应用的话)自动装载bean。 有没有什么办法可以使用@Autowired注解基于我们在Spring的XML文件中作为autowire =“byName”而没有注释的bean名称?

spring 3自动assembly和junittesting

我的代码: @Component public class A { @Autowired private B b; public void method() {} } public interface X {…} @Component public class B implements X { … } 我想单独testingA级。我是否必须模拟B级? 如果是的话,怎么样? 因为它是自动assembly的,并且没有可以发送嘲弄对象的setter。

注入和资源和自动assembly注释

@Inject和@Resource和@Autowired注释之间有什么区别? 我们应该什么时候使用它们?

@Autowired和静态方法

我有@Autowired服务,必须在静态方法中使用。 我知道这是错误的,但我不能改变目前的devise,因为它需要很多工作,所以我需要一些简单的黑客。 我不能改变randomMethod()是非静态的,我需要使用这个autowired bean。 任何线索如何做到这一点? @Service public class Foo { public int doStuff() { return 1; } } public class Boo { @Autowired Foo foo; public static void randomMethod() { foo.doStuff(); } }

intellij错误地说没有findautowired存储库的types的bean

我创build了一个简单的unit testing,但IntelliJ不正确地将其突出显示为红色。 标记为错误 没有豆子? 正如你可以看到它通过testing? 所以它必须是Autowired?

从Spring自动assembly中排除子包?

有没有一种简单的方法来排除在Spring 3.1中的自动assembly的包/子包? 例如,如果我想包含一个com.example基础包的组件扫描,是否有一个简单的方法来排除com.example.ignore ? (为什么?我想从集成testing中排除一些组件)