autowired

Autowired Null Pointer Exception

假如想象 提交于 2019-12-31 04:01:06
问题 I have a filter to save requests to DB. But I get NullPointerException on autowired field: inboundRequestLogStore. I've tried the suggestion from Using some beans in Filter bean class? (I've added SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(this, filterConfig.getServletContext()); to the filter init method and defined a bean in my root-context.xml ) and now it works for the RequestLogFilter class. But, in the InboundRequestLogStore class I have another autowired filed

@Autowire failing with @Repository

陌路散爱 提交于 2019-12-31 02:18:07
问题 I am not being able to make @Autowire annotation work with a @Repository annotated class. I have an interface: public interface AccountRepository { public Account findByUsername(String username); public Account findById(long id); public Account save(Account account); } And the class implementing the interface annotated with @Repository : @Repository public class AccountRepositoryImpl implements AccountRepository { public Account findByUsername(String username){ //Implementing code } public

JMeter, JUnit and Spring Java configuration

一个人想着一个人 提交于 2019-12-30 17:24:36
问题 Is it possible to run JMeter with the JUnit plugin/sampler and Spring Java configuration? When I try to do this, the Spring autowired beans are not being created and although the test case runs, because the beans have not been created, I get null pointer exceptions. I am using the Spring annotation @SpringJUnit4ClassRunner and @ContextConfiguration to configure the JUnit test (which works). The goal is to be able to write JUnit test cases that can be measured for performance using JMeter. 回答1

JMeter, JUnit and Spring Java configuration

馋奶兔 提交于 2019-12-30 17:24:24
问题 Is it possible to run JMeter with the JUnit plugin/sampler and Spring Java configuration? When I try to do this, the Spring autowired beans are not being created and although the test case runs, because the beans have not been created, I get null pointer exceptions. I am using the Spring annotation @SpringJUnit4ClassRunner and @ContextConfiguration to configure the JUnit test (which works). The goal is to be able to write JUnit test cases that can be measured for performance using JMeter. 回答1

Java WAR - Load Spring beans from an external JAR

强颜欢笑 提交于 2019-12-30 10:05:03
问题 I would like to load inside my Spring MVC Web Application (packaged as WAR) some Spring framework beans annotated with @Service from an external jar, which is in charge of accessing a database and located in the classpath under /WEB-INF/lib. If possible, it would be desirable to load them automatically using the @Autowired annotation. I have followed successfully the solution in this link1: this.ctx = new ClassPathXmlApplicationContext("services-context.xml"); this.myAService = ctx.getBean(

@Autowired objects getting null value

浪尽此生 提交于 2019-12-30 08:24:33
问题 Trying to set up a project but fail at Autowiring objects through Spring. package se.hsr.web; public class TestRunner { public static void main(String[] args) { ContactDAO cd = new ContactDAOImpl(); Contact contact = new Contact(); contact.setFirstname("Zorro"); cd.addContact(contact); } } package se.hsr.web; Running this gives me a NullPointerException when cd.addContact is invoked. The ContactDaoImpl: import org.hibernate.SessionFactory; import org.springframework.beans.factory.annotation

What is the cleanest way to autowire Spring Beans in a JSP?

让人想犯罪 __ 提交于 2019-12-30 03:16:10
问题 We're currently adding some new features to an old webapp which was using only JSP without any framework for the front. We have added Spring recently, and we would like to autowire our beans in our modified JSP, while not rewriting everything to use SpringMVC, Struts2 or Tapestry5. We're using autowiring by type, so it leads to get some code like this in the JSP, while previously getting the web application context ( as "wap") : MyDao myDao = (MyDao) wap.getBeansOfType(MyDao.class).values()

How to dynamically inject a service using a runtime “qualifier” variable?

£可爱£侵袭症+ 提交于 2019-12-29 03:37:05
问题 I can't find a simple way to inject a component/service given a runtime value. I started reading @ Spring's doc: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.html#beans-autowired-annotation-qualifiers but I can't find there how to variabilize the values passed to the @Qualifier annotation. Let's say I've got a model entity with such interface: public interface Case { String getCountryCode(); void setCountryCode(String countryCode); } In my client code, I

spring 3 autowiring and junit testing

随声附和 提交于 2019-12-29 02:39:13
问题 My code: @Component public class A { @Autowired private B b; public void method() {} } public interface X {...} @Component public class B implements X { ... } I want to test in isolation class A. Do I have to mock class B? If yes, how? Because it is autowired and there is no setter where i could send the mocked object. 回答1: I want to test in isolation class A. You should absolutely mock B, rather than instantiate and inject an instance of B. The point is to test A whether or not B works, so

Spring autowire a list

半腔热情 提交于 2019-12-28 05:17:08
问题 Is it possible to use @Autowired with a list? Like I have properties file with mimetypes and in my class file I have something like this @Autowired private List<String> mimeTypes = new ArrayList<String>(); 回答1: Spring 4 supports the ability to automatically collect all beans of a given type and inject them into a collection or array. Example: @Component public class Car implements Vehicle { } @Component public class Bus implements Vehicle { } @Component public class User { @Autowired List