autowired

groovy spock mocking spring autowired beans

旧巷老猫 提交于 2019-12-11 11:25:02
问题 I have bean: @Service public class EQueueBookingService { @Autowired public EQueueBookingClient eQueueBookingClient; And I try to write some test for this bean EQueueBookingService using Spock. https://code.google.com/p/spock/wiki/SpockBasics My mock is class EQueueBookingServiceTest extends Specification { @Autowired EQueueBookingService testedService; EQueueBookingClient eQueueBookingClient = Mock(EQueueBookingClient); def setup() { testedService.eQueueBookingClient = eQueueBookingClient; }

Spring - autowired fields are null

给你一囗甜甜゛ 提交于 2019-12-11 09:06:10
问题 I faced a problem with Spring Framework: @Autowired are null, but Spring doesn't throw any exceptions, and I can't understand, why are these fields null. I have a class: package com.processing.gates; public class Main { private final ApplicationContext context = Context.getContext(); @Autowired private PaymentGateFactory paymentGateFactory; @Autowired private CalculatorChooser calculatorChooser; //... } And for example I have the following class: package com.processing.gates.comission;

Spring autowire not behaving as expected

℡╲_俬逩灬. 提交于 2019-12-11 08:36:01
问题 I have tried to autowire a bean for a test class using @Autowire , however the bean is not wired and I get this exception: Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.abc.MyDaoHibernateImpl] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} My test class looks like this: package

Could we autowire an interface without any implementation in Spring?

北慕城南 提交于 2019-12-11 05:49:32
问题 We have to share our code base with a partner for developing, but we don't want to reveal the implementation of some services. Say we have an interface FooService and its implementation FooServiceImpl . public interface FooService { void doSomething(); } @Service public class FooServiceImpl implements FooService { @Override public String doSomething(); { ... } } Many other classes autowire this service in and call doSomething(). For example: @Service public class BarServiceImpl implements

How to make @autowire work in spring when creating instance manually

早过忘川 提交于 2019-12-11 05:13:21
问题 I have a java interface say ITest implemented by two classes Class1 and Class2. Now I have a factory class which I use to decide which implementation to return. like if(something) return new Class1() else return new Class2() Problem is that I have autowired field in Class1 which doesn't get instantiated,, but the same autowiring works in other classes which were instantiated via autowiring. Here is code for Class1 @Componene public Class1 implements ITest{ @Autowired private SomeClass obj; }

Symfony - MemcachedAdapter::__construct() must be an instance of Memcached, string given

本小妞迷上赌 提交于 2019-12-11 04:43:05
问题 This is rather bizarre. I have set up caching with Memcached as follows: framework.yaml framework: cache: app: app.memcached_adapter services.yaml app.memcached_client: class: Memcached factory: 'Symfony\Component\Cache\Adapter\MemcachedAdapter::createConnection' arguments: [['%app.memcached.dsn.1%', '%app.memcached.dsn.2%']] public: true app.memcached_adapter: class: Symfony\Component\Cache\Adapter\MemcachedAdapter arguments: - '@app.memcached_client' public: true I am able to clear cache in

How to get access to ServletContext inside of an @Configuration or @SpringBootApplication class

折月煮酒 提交于 2019-12-11 04:06:30
问题 I'm attempting to update an old Spring application. Specifically, I'm trying to pull all of the beans out of the old xml-defined form and pull them into a @SpringBootApplication format (while dramatically cutting down on the overall number of beans defined, because many of them did not need to be beans). My current issue is that I can't figure out how to make the ServletContext available to the beans that need it. My current code looks something like this: package thing; import stuff

Spring session scoped objects in @Scheduled

删除回忆录丶 提交于 2019-12-11 03:54:25
问题 In spring, I have a lot of code that uses session beans defined like this: @Scope(value="session", proxyMode=ScopedProxyMode.TARGET_CLASS) In my webapplication all is fine, since a session scope is available. In my JUnit tests, all is also fine since i'm using a WebContextTestExecutionListener (link) that registers a thread scope for the session scope But when a method with @Scheduled is called, I get an exception since there is no session scope. Now my question is: How can I register a

Autowired error spring

天涯浪子 提交于 2019-12-11 03:43:31
问题 I am new to spring. Previous I have used to configure the auto wiring using spring- context xml. Now my project we are using annotation directly to inject the bean. I am getting following exception when I try to auto wire Mongo repository. Below is the sample code. StagingDocumentServiceImpl: @Service public class StagingDocumentServiceImpl implements StagingDocumentService { private static final Logger logger = Logger.getLogger(StagingDocumentServiceImpl.class); @Autowired private

how do I configure autowire in spring

╄→尐↘猪︶ㄣ 提交于 2019-12-11 02:47:28
问题 how do I configure autowire in spring 回答1: Add the context schema to your configuration XML and use the @Autowired annotation: http://static.springsource.org/spring/docs/2.5.x/reference/beans.html#beans-annotation-config 来源: https://stackoverflow.com/questions/1516704/how-do-i-configure-autowire-in-spring