autowired

Spring Bean Autowiring error

梦想与她 提交于 2019-12-10 13:32:55
问题 I am trying to implement email functionality in my app but I keep getting No matching bean of type [org.springframework.mail.javamail.JavaMailSenderImpl] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Can anyone point out what I am doing incorrectly? The xml config for the bean is: <beans:beans xmlns="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www

Spring and auto-wiring: NullPointerException

有些话、适合烂在心里 提交于 2019-12-10 10:57:48
问题 I'm trying to get a grip on auto-wiring in Spring, but I can't seem to properly instantiate the bean (a DocumentBuilder ). I have created a custom JSP tag as such: public class MyTag extends SimpleTagSupport { @Autowired private DocumentBuilder documentBuilder; public void setBuilder(DocumentBuilder builder) { this.documentBuilder = builder; } @Override public void doTag() throws IOException { // documentBuilder is null in here! } } This is the servlet configuration: <?xml version="1.0"

Spock How to mock Autowired class' function call within a method

主宰稳场 提交于 2019-12-10 10:45:28
问题 I have a class that I want to test in that looks like this: package com.something; import org.springframework.beans.factory.annotation.Autowired; public class ClassToTest implements InterfaceToTest{ @Autowired AnotherService serviceA; @Override public List<String> methodToTest(List<String> randomVar){ ... String stringA = serviceA.someFunction(randomVar); ... } } How can I mock the results from the call to serviceA.someFunction(randomVar) to return any String of my choice when testing with

Why doesn't the spring @Autowired work with java generics

别来无恙 提交于 2019-12-10 10:07:57
问题 Inspired by spring data awesomeness I wanted to create a abstract RESTController that I could extend for a lot of my controllers. I created the following class: @Controller public abstract class RESTController<E, PK extends Serializable, R extends PagingAndSortingRepository<E, PK>> { @Autowired private R repository; @RequestMapping(method=RequestMethod.GET, params={"id"}) @ResponseBody public E getEntity(@RequestParam PK id) { return repository.findOne(id); } ... } I was hoping that the

Mocking Spring beans

时光怂恿深爱的人放手 提交于 2019-12-10 08:48:40
问题 I'd like to continue this question. These answers foo and bar are exactly what I would need. But for the bar example spring doesn't infer the type of bean that is returned from generic mock() method. But actually it's exactly the same as in the MockFactoryBean case, that is working. class MockFactoryBean<T> implements FactoryBean<T> { private Class<T> type; public void setType(final Class<T> type) { this.type = type; } @Override public T getObject() throws Exception { return (T) Mockito.mock

Spring JUnit4 manual-/auto-wiring dilemma

给你一囗甜甜゛ 提交于 2019-12-10 05:24:34
问题 I ran into an issue that can only be explained with my fundamental lack of understanding of Spring's IoC container facilities and context setup, so I would ask for clarification regarding this. Just for reference, an application I am maintaing has the following stack of technologies: Java 1.6 Spring 2.5.6 RichFaces 3.3.1-GA UI Spring framework is used for bean management with Spring JDBC module used for DAO support Maven is used as build manager JUnit 4.4 is now introduced as test engine I am

How does Mockito @InjectMocks work?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-09 02:14:17
问题 Here's my question: I have several web services classes to test that all inherit their methods from a generic service. Rather than write a unit test for each, I figure I can break the test suite down by functional areas (i.e. three groups of test methods, each relying on a different underlying DAO method call). What I propose to do is: @Mock StateDAO mockedStateDao; @Mock CountyDAO mockedCountyDao; @Mock VisitorDAO mockedVisitorDao; then call: @InjectMocks CountyServiceImpl<County>

EJB3 with Spring

≡放荡痞女 提交于 2019-12-09 01:21:32
问题 I have understood that if I use EJB in Spring context, I get all the same benefits as if I was using it in "pure" EJB3 environment, is this true? I have googled but can't find a definitive, clear answer. For example, let's say I have a session bean that updates some tables in the database and it throws a System Exception. In "pure" EJB3 environment the transaction is rolled back. What if I for example @Autowire this bean using Spring, does Spring take care of the transaction handling same way

How to overwrite Spring service beans by name, using annotations only

给你一囗甜甜゛ 提交于 2019-12-08 18:10:59
问题 Given I have a Spring bean configured as @Service("myService") public class DefaultService extends MyService { } and a class using this bean public class Consumer { @Autowired @Qualifier("myService") private MyService service; ... } I now want my project, that includes the preceding classes, to have Consumer another implementation of MyService being injected. Therefore I would like to overwrite the bean myService @Service("myService") public class SpecializedService implements MyService { }

Parameter 0 of method setUserService in <method> required a bean of type <service> that could not be found

萝らか妹 提交于 2019-12-08 18:03:36
问题 I have been through this issue and couldn't find what is going on.... tried to @ComponentScan, tried to name my services, none seems to work. Error: 03:35:05,193 WARN [org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext] (ServerService Thread Pool -- 81) Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfiguration':