autowired

it's ok to define 2 same beans in xml and configuration

允我心安 提交于 2019-12-08 12:17:51
问题 I created an xml context config, and also an annotation-based context configuration class,each creates a bean with same id, same class. so I thought that this would create a conflict because spring would say "can't find a unique instance of type ttt.TTT" (I have seen this error elsewhere). but surprisingly, the following code actually runs fine, and the bean chosen is the one from xml. if I cross out either of the bean definitions, it works fine too. so, why am I not getting a bean definition

Spring MVC when autowired HttpSession will be created?

大兔子大兔子 提交于 2019-12-08 12:13:32
问题 Issues in using AutoWired HttpSession: LoginController calls LoginService passing HttpServletRequest as parameter. I've autowired HttpSession like this in few other annotated classes (but NOT in LoginService): @Autowired private HttpSession httpSession; In LoginService class, if I try to get session by calling request.getSession(false) I receive null in some instances. If I try to get session by calling request.getSession(true) I am ending up with two HttpSession objects (one here and another

spring/scala: Possible to autowire bean dependencies?

爱⌒轻易说出口 提交于 2019-12-08 12:09:46
问题 I'm trying do the following without xml configuration in spring (in scala) <beans ... > ## (1) ## Auto create a bean by classname ## Auto-wires properties of x.y.Bar <bean id="baz" class="x.y.Baz"/> ## (2) ## Create a x.y.Foo and auto-wire the property <bean id="foo" class="x.y.Foo"> <property name="b" ref="baz"/> </bean> </beans> where we have: class Baz {} class Foo { @Autowired //? @BeanProperty val baz:Baz = null } I have the following test setup: @Configuration class Config { //

Testing a controller with an auto wired component is null when calling the controller from a test case

我的梦境 提交于 2019-12-08 11:48:33
问题 I have a controller @RestController public class Create { @Autowired private ComponentThatDoesSomething something; @RequestMapping("/greeting") public String call() { something.updateCounter(); return "Hello World " + something.getCounter(); } } I have a component for that controller @Component public class ComponentThatDoesSomething { private int counter = 0; public void updateCounter () { counter++; } public int getCounter() { return counter; } } I also have a test for my controller.

Compile Time Weaving Null Pointer Exception

ⅰ亾dé卋堺 提交于 2019-12-08 10:28:20
问题 Edit 7: The problem seems to be how to get @Configurable working with HttpSessionListener , a workaround is suggested, but I'dd prefer not to to interact with the WebApplicationContext directly: @Configurable(autowire = Autowire.BY_TYPE, preConstruction = true) public class SessionListener implements HttpSessionListener { private static final Logger log; @Autowired private A a; @Override public void sessionCreated(HttpSessionEvent se) { a.doSomething(); // <- Throws NPE log.info("New session

spring mvc @Autowired error Unsatisfied 'required' dependency of type

旧城冷巷雨未停 提交于 2019-12-08 09:56:53
问题 I have user service that treat user entity, and @Autowired in user controller class before use user service. so, I got the error: Unsatisfied 'required' dependency of type [class com.yes.service.UserService]. Expected at least 1 matching bean here the codes: userService package com.yes.service; import java.util.List; import java.util.UUID; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.yes.domain.User; import com.yes

Spring and Multithreading

£可爱£侵袭症+ 提交于 2019-12-08 09:27:09
问题 I need to start a variable number of threads which in turn each start a varying number of threads (i.e. i threads where the Ith thread needs to start Ki threads) in a spring application. assuming each of the "I threads" contains an inner class which is autowired how will I generate those instances? So I have an A bean which needs to somehow generate I instances of a bean which needs to be spring managed to satisfy its dependencies. I've written a short sample code of what I think is the base

Autowire session-scoped bean into thread (Spring)

孤人 提交于 2019-12-08 07:36:08
问题 I have a session-scoped bean in Spring that is set within the web context. I have a task that runs as a Callable, and I need access to this bean from within that thread. How should I accomplish this? If I simply attempt autowiring the bean I get the error message: Scope 'session' is not active for the current thread The session-scoped bean I am injecting looks like this: <bean id="userInfo" class="com.company.web.UserInfoBean" scope="session"> <aop:scoped-proxy /> </bean> And the class I am

javax.el.PropertyNotFoundException : Target Unreachable, identifier 'login' resolved to null Spring + JSF [duplicate]

本小妞迷上赌 提交于 2019-12-08 03:05:50
问题 This question already has answers here : Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable (14 answers) Closed 3 years ago . I can't resolve my problem for getting null with my @Autowired service. Here's my code. My configuration file applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema

hibernate validator without using autowire

扶醉桌前 提交于 2019-12-07 17:38:29
I'am currently working on a Jersey project and decided to use Hibernate validator for the parameter validations. All dependencies injected on the Endpoint classes are properly initialized. However for those dependencies in the ConstraintValidator classes, it always throw a NPE. So i followed the guide on Spring+hibernate guide and registered bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean" and used the @Autowired annotation for the services in the ConstraintValidator class which needs to be injected. are there side effects of using it? Is