w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
What is the difference between spring factory-method and factory-bean?
You can find documentation about this here. See section 3.2.3.2 and 3.2.3.3. factory-method is used to point to a static method in legacy code that can be used to create a bean. Quite similar to using a static factory method to create a bean, is the use of an instance (non-static) factory method, where a factory method of an existing bean from the factory is called to create the new bean. This is what factory-bean is for.

Categories : Java

Abstract Factory Pattern - dependency between concrete products
1 - I think your SimpleGraphicsFactory is indeed a good example of an Abstract Factory. 2 - It is completely appropriate that SimpleSquare casts to SimpleCanvas because they are both part of the same "family", created by the same concrete factory. Recall the definition of Abstract Factory (emphasis is mine): Provide an interface for creating families of related or dependent objects without specifying their concrete classes. The implication of this design pattern is that the classes created by it can assume / require they are being used with classes from the same family. To use another example from the .NET world, the System.Data namespaces acts in a similar way. Objects from the System.Data.Sql namespaces will not work with objects from System.Data.Oracle. You cannot pass a S

Categories : C#

Java Factory Pattern how to let concrete products instantiate themselves
This is a fundamental limitation in the Java class model; the static initializer that registers the class with the factory won't get run until the class gets loaded. The best solution for this problem is usually the Service Provider Interface, which lets you list the classes that implement some interface in a jar and then scan for all matching implementations.

Categories : Java

Spring security- org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.filterChains'
Looking at the stacktrace information it appears as if you have conflicting framework jars in your classpath. When using maven use mvn dependency:tree to figure out which dependencies get used, I suspect that there is an older spring-beans.jar in your classpath.

Categories : Java

org.springframework.beans.factory.BeanDefinitionStoreException
Your bean transactionApi is expecting a property to be set using Spring's replaceable properties. The error tells you the replaceable property is wu.enrollment.time. See here for Spring's documentation on how it works.

Categories : Java

org.springframework.beans.factory.parsing.BeanDefinitionParsingException
please replace the following with your root-context.xml, security_config.xml files. Change according to your version. This is caused by namespace problem <?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:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd http://www.springframework.

Categories : Java

I am getting this error org.springframework.beans.factory.BeanCreationException
In your applicationContext.xml file i dont see any bean with name or id as sessionFactory and you are refering to it <property name="sessionFactory" ref="sessionFactory"/> and at one more place. Please define a bean with name or id as sessionFactory.

Categories : Java

How do I fix the org.springframework.beans.factory.BeanCreationException error in my Grails application?
After working all day on this problem and getting valued input from comments, I have found the solution to my problem. 1) Dev was not a valid user for SQL Server so I added it in phpMyAdmin as well as the security folders for the database. I also re-migrated the database after adding user dev to MySQL. 2) plugins.searchable=0.6.4 needed be commented out from the application.properties file in order to fix the stack trace errors. 3) The Grails Runtime Exceptions were solved by going through the database tables and correcting the data types that were improperly migrated. All binary data types had to be changed to bit type. The grails app now runs flawlessly. Hope this helps anybody else out there with this problem!

Categories : Sql Server

sprin2.5 + quartz scheduler...org.springframework.beans.factory.BeanCreationException
you have to include quartz related jar in your classpath, which version of quartz are you using? according to the link you posted, you should add quartz dependency to your pom.xml <dependency> <groupId>quartz</groupId> <artifactId>quartz</artifactId> <version>1.5.1</version> </dependency> if you are not using maven, include quartz.jar in your classpath as you do with spring-context-support-2.5.6.jar --edit-- seems odd, you don't happen to have multiple copies of the quartz in WEB-INF/lib? what is the com.springsource.org.quartz-1.6.2.jar for? try exclude it from WEB-INF/lib

Categories : Java

Exception starting filter springSecurityFilterChain - org.springframework.beans.factory.NoSuchBeanDefinitionException
I might be wrong, but if you use AnnotationConfigWebApplicationContext and specify only a package name in contextConfigLocation, Spring will scan that package only for classes with a stereotype annotation (@Component, @Controller, @Service, etc), so your WebAppConfig is basically ignored. Try giving the fully qualified name of WebAppConfig as contextConfigLocation.

Categories : Spring

Designing a factory framework with Guice, enumerations, and static factory methods
You've got two problems here, really: How to give Guice the input needed to decide what kind of object to make How to get Guice to run the code to make the right object Problem 1. Guice really really wants to just make a big graph of objects on startup using information provided at startup-time. Yet a lot of what makes it powerful comes from giving it the ability to vary its behavior depending on conditions at runtime - so a lot of frameworks that build on Guice do things to enable that - Servlet support has its request scope which lets a servlet request be injected, and so forth. There are three basic ways to give objects created on-the-fly to Guice to use when creating objects: Assisted Inject Custom scopes Write a one-off Provider<Animal> which gets hold of the relevant d

Categories : Java

Abstract factory method; changing the factory passed to an object
Your problem is here: //the DrinkingMethod in the VobFactory class gives us different output data.BoozeFactory = new VobFactory(); //this is what's causing problems data.BoozeFactory.CreateWhiskey(); data.Whiskey.DrinkingMethod(); You never assign the new whiskey to the data.Whiskey property, you create it and then discard it instantly. You should be writing your second line as this: data.Whiskey = data.BoozeFactory.CreateWhiskey(); Or, better yet, have the drinker have a method that does this for it.

Categories : C#

django factory boy factory with OneToOne relationship and related field
I believe this is because you have a circular reference in your factory definitions. Try removing the line account = factory.RelatedFactory(AccountFactory) from the UserFactory definition. If you are always going to invoke the account creation through AccountFactory, then you shouldn't need this line. Also, you may consider attaching a sequence to the name field, so that if you ever do need more than one account, it'll generate them automatically. Change: username = "bob" to username = factory.Sequence(lambda n : "bob {}".format(n)) and your users will be named "bob 1", "bob 2", etc.

Categories : Python

Factory method, why we use a static call to get the object from factory
You have to ask yourself: Will different objects of Factory class behave differently? In this case, will they create new objects in a different manner? The answer is No. If a method is not object scoped, its a perfect candidate for static.

Categories : Java

Is it OK for my domain objects use a factory method, or factory layer, when they need to?
If a pet cannot exist without it's user, it does not mean a user can exist without pet. The question is whether the pet needs it's user and vice versa. I can pretty much think about both existing alone, and cross-referencing them might either be a good idea or not, depending on the problem. Generally speaking I'd say it's rather not so good, because it means that the user can interact with the pet, and the pet can interact with the user, and both interactions can trigger reverse interactions, resulting in an endless loop. A safer solution would be to have an object that contains both user and pet and directs all interactions between them: A user-pet-relationship. If you state that you cannot inject an objects dependencies, then you are doing something wrong. If you want to inject a fact

Categories : PHP

Add FactoryGirl factory after initial define
A coworker showed me how to do this. You have to override 'initialize_with' and use the special 'attributes' variable to get the job done. factory :my_table_temp_loading_table, :class => ActiveRecord::Base do initialize_with do MyTable.create_subclass(attributes[:subclass_id]).new(attributes) end my_table_traits end

Categories : Ruby

Generic Key Pool Factory setting parameters
You would be using constructor args. Here's an example lifted from Spring docs: <bean id="exampleBean" class="examples.ExampleBean"> <constructor-arg><ref bean="anotherExampleBean"/></constructor-arg> <constructor-arg><ref bean="yetAnotherBean"/></constructor-arg> <constructor-arg type="int"><value>1</value></constructor-arg> </bean>

Categories : Java

Spring MVC bind hibernate session factory other thread in spring web mvc
You need to either go through AOP decorated transactional bean (e.g. your service layer annotated with @Transactional), or you need to use TransactionTemplate: new TransactionTemplate(txManager).execute(new TransactionCallback<Void>() { @Override public Void doInTransaction(TransactionStatus status) { // Your Hibenrate stuff return null; } });

Categories : Spring

java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet and org.springframework.beans.factory.Aware
in general it missing the spring jar seems or add the application-context to classpath and request listners <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:application-context.xml </param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class> </listener>

Categories : Spring

A JMS-Queue-Factory-Bean --> Reuse a injected jms queue in different beans
In your code you have managed to centralize the resource declration/injection, but at your usage site you still need to address each queue individually. So not much has been gained compared with direct injection. It seems that you are trying to have something like an array of queues together with resource injection, but resource injection in that case does not really scale: Each new queue requires a deployment. In your case I suggest using a manual JNDI lookup in an iteration. Then you can put the queues in an array/list for further processing. You could even pass the number of queues as a parameter into the method, and so the number of queues can be changed dynamically at run-time: Pseudo-code (not tested, just for illustration): InitialContext ic = new InitialContext(); Queue[] qs

Categories : Java

How do I use Ninject.Extensions.Factory to bind a objects from a generic interface?
After a lot of playing around... When you configure the kernel, you have to tell it how to create the types IRequestHandler<GetEngineOptionsRequest> and IRequestHandler<GetEngineOptionsRequest, GetEngineOptionsResult>: kernel.Bind<IRequestHandler<GetEngineOptionsRequest>>().To<ConcreteImplementationOfThisInterface>(); kernel.Bind<IRequestHandler<GetEngineOptionsRequest, GetEngineOptionsResult>>().To<GetEngineOptionsRequestHandler>(); Then create the factory interface. You can have generic or non-generic methods on it - I've included examples of both. Note that method names starting with 'Get' are special - read this. You could probably go down that route, but I won't here. public interface IRequestHandlerFactory { // Generic IReq

Categories : C#

Resolve automatic factory from named registration for generic type
Unfortunately you can't use RegisterAssemblyTypes in this instance - it doesn't fully handle generic registrations the way you need to do it (you need to explicitly register each concrete command handler against it's implemented interface, including the generic type of that interface). You can use the following as your registration instead: assembly.GetTypes() .Where(type => type.Name.EndsWith("CommandHandler")) .ToList() .ForEach(t => builder.RegisterType(t) .Named("concreteCommandHandler", typeof (ICommandHandler<>) .MakeGenericType(t.GetInterfaces()[0].GenericTypeArguments[0]) )); builder.RegisterGeneric(typeof(FactoryCommandHandler<>) .WithParameter( (p, c) => true, (p, c) => c.ResolveNamed("concreteCom

Categories : C#

Possible to compile-time check constructor parameters for generic factory function?
Not really, since you're using reflection which is a runtime technology... The only way the compiler would become aware of the inability to create your instance would be to run your code... At least until the CAAS shows up. One option might be to approach this differently: force a new() constraint on your generic type in the method (makes sure that all types have a parameterless constructor) and then maybe map the constructor parameters as properties instead on your types? Maybe not ideal if you want immutability but reflection can write to private types etc. anyway... This is pretty much the kind of scenario that the ArgumentException class was built for... Throw it if stuff doesn't work as expected.

Categories : C#

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'helper' . No unique bean of type [java.lang.String]
Try Droping the @Autowired annotation in Ctor and configuring it in xml: <bean id="helper" class="test.Helper"> <constructor-arg ref="clientFactory" /> <constructor-arg ref="modelManager" /> <constructor-arg type="java.lang.String" value="http://test.com" /> <constructor-arg ref="securityService" /> </bean>

Categories : Java

does spring has some inbuilt factory implementation?
This is possible, and documented in the manual: In most application scenarios, most beans in the container are singletons. When a singleton bean needs to collaborate with another singleton bean, or a non-singleton bean needs to collaborate with another non-singleton bean, you typically handle the dependency by defining one bean as a property of the other. A problem arises when the bean lifecycles are different. Suppose singleton bean A needs to use non-singleton (prototype) bean B, perhaps on each method invocation on A. The container only creates the singleton bean A once, and thus only gets one opportunity to set the properties. The container cannot provide bean A with a new instance of bean B every time one is needed. A solution is to forego some inversion of control. You can m

Categories : Java

Implementing custom factory pattern in Spring
Well what do you think about following way? : public class CustomFactory { // Autowire all MyService implementation classes, i.e. MyServiceOne, MyServiceTwo, MyServiceThree @Autowired @Qualifier("myServiceBeanOne") private MyService myServiceOne; // with getter, setter @Autowired @Qualifier("myServiceBeanTwo") private MyService myServiceTwo; // with getter, setter @Autowired @Qualifier("myServiceBeanThree") private MyService myServiceThree; // with getter, setter public MyService getMyService(){ // return appropriate MyService implementation bean /* if(condition_for_myServiceBeanOne) { return myServiceOne; } else if(condition_for_myServiceBeanTwo) { return myServiceTwo;

Categories : Spring

Spring ServiceLocator or pure factory pattern?
As an option you can use list injection: public class SomeService { @Autowired private List<Parser> parsers; public doSomethingWithParser(...) { ... Parser parser = getParser(JsonParser.class); parser.parse(...); ... } private Parser getParser(Class<Parser> targetClass) { Parser result = null; for(Parser parser : parsers) { if(parser.getClass().equals(targetClass)){ result = parser; } } return transformer; } } Even better, you can add Parser.isCompatibleWith(SomeInput input) method to simplify paser detection code.

Categories : Java

How to create a spring bean from an enum singleton's factory method
This ought to work: <util:constant id="exchangeFactory" static-field="com.xeiam.xchange.ExchangeFactory.INSTANCE" /> <bean id="mtGoxExchange" factory-bean="exchangeFactory" factory-method="createExchange"> <constructor-arg value="com.xeiam.xchange.mtgox.v2.MtGoxExchange" /> </bean> Give it a shot.

Categories : Java

Webservice using CXF and Spring 3 webserviceTemplate gets error on Jboss 5 due to Soap Message Factory
I encountered the same issue and finally noticed that the exception message suggested that a property "messageFactory" could not be set on the SaajSoapMessageFactory. This is confusing, because "messageFactory" is also the name of the bean being created as SaajSoapMessageFactory. Spring was failing to set the messageFactory property of SaajSoapMessageFactory to the same SaajSoapMessageFactory bean. I found two solutions: My element included default-autowire="byName". By removing this, the issue disappeared. Without removing the default-autowire attribute, I explicitly set the messageFactory property to null. This is a bit awkward but also appears to work: <bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"> <property name="soa

Categories : Java

How to inject Spring Bean for factory method requiring MyClass.class parameter
You can specify the constructor-arg element <bean id="preferences" class="java.util.prefs.Preferences" factory-method="userNodeForPackage"> <constructor-arg type="java.lang.Class" value="com.path.MyController" /> </bean> This is explained in the official documentation here, section 5.4.1. Arguments to the static factory method are supplied via elements, exactly the same as if a constructor had actually been used. The type of the class being returned by the factory method does not have to be of the same type as the class that contains the static factory method, although in this example it is. An instance (non-static) factory method would be used in an essentially identical fashion (aside from the use of the factory-bean attribute instead of the cl

Categories : Java

Spring session factory not finding mapping files in multiple directories with same class path
You are using maven. And since you put your Bar mapping into the test resource directory, it is only available when running tests. I assume you have a persistence-unit configured similar to the example below <persistence-unit ...> <class>something.Foo</class> <class>something.Bar</class> </persistence-unit> What happens at start-up is that Spring starts Hibernate, hibernates reads the persistence-unit and asks the factory for the mappings. But remember, Bar is only a test class. So Spring finds the mappings from src/main/resources, but since it does not run as a test, it does not see src/test/resources.

Categories : Spring

return generic IEnumerable when passing concrete type parameter for a generic method
You cannot convert the Type class to a generic T parameter without using reflection. The parameter also needs to be present as part of the method. Jon Skeet was using type inference by example combined with generics in order to guarantee type safety and simplify the generic code. Unfortunately you will lose that type safety using Type and reflection. private IEnumerable<EntityObject> GetFilteredData(Type entityType, SortedList<string, string> filterList, List<int> weeks) { var method = typeof(<class>).GetMethod("GetFilteredDataImpl"); var generic = method.MakeGenericMethod(entityType); return (IEnumerable<EntityObject>)generic.Invoke(this, new[] {

Categories : C#

Reflection - Navigate a non-generic method from a generic type definition to a concrete one
You can use the MakeGenericType method, like this: m.DeclaringType.MakeGenericType(typeof(int)) and then probably GetMethod again if you really want to go this way: m.DeclaringType.MakeGenericType(typeof(int)).GetMethod("Method"); However, consider Jon Skeet's comment for simpler solution.

Categories : C#

Autocomplete with generic types in concrete class of implementation
Eclipse would ignore the generic type if it auto-completed with new ArrayList(), which is an instance of the raw type. But it auto-completes with new ArrayList<>(), which uses the diamond operator. This operator exists since Java 7 and is equivalent to new ArrayList<String>(), but without the redundancy. So, in short, Eclipse does the right thing.

Categories : Java

it's ok to define 2 same beans in xml and configuration
Spring Application Contexts behavior is to 'overwrite' by default. that is, as the beans are being loaded up into the factory, if the definition exists (either by annotation of xml), it will simply overwrite it with the next definition. (to see which one is getting loaded, try changing a property value to see in which order it's being loaded) have a look here for a better explanation

Categories : Spring

ThreadPoolExecutor Future Task -exception with spring bean injection-spring-beans-2.0
The issue isn't with anything coming from java.util.concurrent or weblogic. What weblogic is telling you is that one of its registered threads has been waiting longer then 10 minutes for the get() to return. So why hasn't it returned? That is because the Callable you submitted has not yet returned. You should check the callable you submit to the executor and find out why that is still in the call() method. For instance, if I write something like Weblogic-Thread-1 Future f= e.submit(new Callable(){ public Object call(){ Thread.sleep(700000); return null; } }); Weblogic-Thread-2 f.get(); //will sit here and suspend for 700 seconds So you need to see why the task you submitted has not yet completed.

Categories : Java

How to configure Spring BeanPostProcessor to get invoked only for a defined set of spring managed beans
I doubt if you can control purely by xml configuration/annotation. You can however control it within the code of the BeanPostProcessor: public Object postProcessBeforeInitialization(Object bean, String beanName) { if (thisBeanIsOfConcernToMe(bean, beanName){ doPostProcessTasks()... } } If this BeanProcessor is not under your control, then overriding the bean and delegating to the parent for certain custom conditions would be another way to go: public MyBeanProcessor extends NotUnderControlBeanPostProcessor { .... public Object postProcessBeforeInitialization(Object bean, String beanName) { if (thisBeanIsOfConcernToMe(bean, beanName){ return super.postProcessBeforeInitialization(bean, beanName) }else{ return bean; } }

Categories : Java

Factory not registered
You have your factory definition in the wrong file, according to your question it is in user.rb. This needs to be in a factories.rb in your test folder (spec) if you use rspec # user.rb FactoryGirl.define do factory :user do |f| f.email "aabb@hh.de" f.password "ruby" f.password_confrimation "ruby" end end Change above to this, (Also you don't need the f variable) # spec/factories.rb FactoryGirl.define do factory :user do email "aabb@hh.de" password "ruby" password_confrimation "ruby" end end Also as the comments say, make sure gem 'factory_girl_rails' is in your Gemfile, instead of just gem 'factory_girl'

Categories : Ruby On Rails

Specifying Associations in Factory
License belongs to LicenseTemplate FactoryGirl.define do factory :license do start_date { Time.now} end_date { Time.now + 30.days } factory :license_with_template do association :license_template, factory: :license_template end after(:build) do |doc| if doc.license_template doc.agents_count = doc.license_template.agents doc.requests = doc.license_template.requests end end end end the above code gives me two factories 'license' and 'license_with_template'. the after 'build' block initializes the values which need to be initialized before the object is saved.

Categories : Ruby On Rails

"Move Factory" for c++ 11
AR ar = fact.GenerateRA1(std::move(a));//does...reference to a is still around, but destroyed The user requested that you move the contents out of a into the function, she knows that the contents of a might have been moved and knowing the type A she knows what can be done or not with the object a. This is not a problem, this is how things work. //AR ar = fact.GenerateRA1(a); //doesn't compile This is exactly the main point. The compiler rejects this code, so that the user does not need to check whether a is moved out of or not (*), only if the user explicitly requests the move (and thus knows without having to guess) the compiler will move out of the object.

Categories : C++



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.