FAQ Database Discussion Community


Spring: Autowired is null in ejb class

spring,ejb,repository,autowired,inject
I have the following situation: @Controller public class myController { @Autowired private IProxy service; public ModelAndView init(HttpServletRequest request, HttpServletResponse response) throws Exception { List<String> list = service.getName(); } } Then my Service is define as follow: public interface IProxy { public List<String> getName(); } Proxy class is responsible for the...

can't inject Providers mock in JerseyTest

java,mocking,jersey,integration-testing,inject
I'm getting Providers from context in my filter to get defined ObjectMapper public class Filter implements ContainerRequestFilter, ContainerResponseFilter { @Context private Providers providers; @Context private HttpServletRequest request; private ObjectMapper getObjectMapper() { ContextResolver<ObjectMapper> contextResolver = providers.getContextResolver(ObjectMapper.class, MediaType.APPLICATION_JSON_TYPE); if (contextResolver == null) { return new ObjectMapper(); } return contextResolver.getContext(null); } } but...

Cant inject Gson in java with @inject

cdi,inject,producer
Hello i have the following problem, when i load the class without the @inject private Gson gson it runs normaly, but when i put it it throws a exception. Class that calls gson. package core.control; import java.util.List; import javax.inject.Inject; import javax.inject.Named; import com.google.gson.Gson; import core.dao.SistemaDao; import core.model.Sistema; @Named public class...

Mockito @InjectMocks doesn't work for fields with same type

java,unit-testing,mockito,inject
I was very surprised to find out that following simple code example doesn't work for all Mockito versions > 1.8.5 @RunWith(MockitoJUnitRunner.class) public class MockitoTest { @Mock(name = "b2") private B b2; @InjectMocks private A a; @Test public void testInjection() throws Exception { assertNotNull(a.b2); //fails assertNull(a.b1); //also fails, because unexpectedly b2...

Seeking example of how to tell Autofac which service to inject by name

c#,attributes,autofac,inject
I need an attribute like [WithNamed("x")] that will tell Autofac how to inject each 'service' with the correct parameter as shown. The constructor to be injected with two versions of FlagXCtlr: public CoupDo( [WithName("FLAG6")]ItemUserFlagCtrl Flag6Ctlr, [WithName("FLAG5")]ItemUserFlagCtrl Flag5Ctlr) { ... } Registering is done as so: builder.RegisterType<ItemUserFlagCtrl>() .Named<IItemUserFlagCtrl>("FLAG6") .WithParameter("userFlagParm", "FLAG6") .SingleInstance();...

Define bean using factory method in plain Java EE - WITHOUT Spring

java,java-ee,dependency-injection,autowired,inject
I want to create a bean which can be automatically injected (autowired) by plain Java EE, not with Spring. The code I have is this: import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; @ApplicationScoped public class MyConnector { .... private Client client = ClientBuilder.newClient(); .... } I'd like to use dependency injection like that...

PHP-DI annotation not working

annotations,inject,php-di
I have installed php-di 4.4 in a new custom project using composer.Im runing a xampp localhost with php 5.6.3 but I set netbeans for php 5.4 on this project. Im new to php-di, I did use annotations in my android projects but cant seem to make it work here. The...

Guice inject based on annotation value

java,annotations,guice,inject
I would like to use goolge/guice inject a value based on a class i provide with the annotation. AutoConfig annotation @BindingAnnotation @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.PARAMETER, ElementType.FIELD }) public @interface AutoConfig { // default null not possible Class<? extends Provider<? extends ConfigLoader<?>>> provider() default XMLAutoConfigProvider.class; } This is my annotation which allows...

Guice : Inject an ArrayList of Strings

java,arraylist,guice,inject
I'm trying to inject an ArrayList of Strings with the help of Guice. I want to show a panel with many RadioButtons (for example) where an user can select some services to activate. Once selected, I would like to get all the names of the selected services and add them...

Map with accumulator on an array

ruby,inject
I'm looking to create a method for Enumerable that does map and inject at the same time. For example, calling it map_with_accumulator, [1,2,3,4].map_with_accumulator(:+) # => [1, 3, 6, 10] or for strings ['a','b','c','d'].map_with_accumulator {|acc,el| acc + '_' + el} # => ['a','a_b','a_b_c','a_b_c_d'] I fail to get a solution working. I...

Does guice allow injectMembers into a constructor?

java,constructor,guice,inject
My problem is here; I don't know if i can do that with guice: public class Foo { private final Bar bar; @Inject public Foo(Injector injector) { this.bar = new Bar(); injector.injectMembers(bar); } } *bar will be injected correctly or not ? Thank you...

Angular is giving me an injection unresolved error, but my controller isn't asking for any injections

javascript,angularjs,controller,modal-dialog,inject
I have a modal controller that is buggy, so I've been commenting out code to try to figure out the bug. Currently, my modal HTML partial is an empty div tag and my controller is a single console.log, with no arguments or parameters. The $modal.open call only specifies the controller...

Ruby Inject Weird Behavior

ruby,arrays,functional-programming,inject
I'm trying to produce the full permutation of a given array. For example, if the input is fact(2, ['A', 'B']), the output should be [["A", "A"], ["B", "A"], ["A", "B"], ["B", "B"]]. def fact(n, arr) return [[]] if n == 0 nxt = fact(n - 1, arr).freeze arr.inject([]){ |result, elem|...

Ruby inject until sum exceeds a set value and return the index where this occurs

arrays,ruby,inject
With the following array and value: v = 50 a = [10, 20, 25, 10, 15] I want to iterate through the array adding up the values until the sum of these values exceeds the variable v. And then I want to be able to return the index in the...

missing type specifier - int assumed

c,dll,code-injection,inject
I have been trying to solve that problem on these code stacks. I tried to block injection etc. on my executable. I call my function like that: #include "Protect.h" EL_DenyProcessAccess(); error C4430: missing type specifier - int assumed. Note: C++ does not support default-int error C2146: syntax error : missing...