w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
why do I need the prefix 'batch:' in my spring beans
batch is the alias in your XML file for the http://www.springframework.org/schema/batch namespace. You'll have something like this at the beggining of your XML: xmlns:batch="http://www.springframework.org/schema/batch" This means that whenever you're prefixing an element with batch:, you're specifying that the element is the one Spring defines. This is necessary to clear out possible ambiguities (there might be other frameworks around defining the <job> element). It is possible to define a default namespace for all elements in the XML document, so that if no namespace is prefixed, it'll be the one that the declaration is referring to. This default namespace is defined with the xmlns="..." attribute, and is usually assigned to the http://www.springframework.org/schema/beans name

Categories : Xml

How to properly load and configure Spring beans from an external utility jar
Two approaches by which you can solve this : (Please include the dependency as part of pom.xml) To manually include only the required utility beans into this new application-context.xml with the path referring to those class paths. That's the beauty of spring to create the selective bean only. Have a properties file (Include this in the new application-context.xml) <context:property-placeholder location="WEB-INF/utility.properties"/> <import resource="${application.path.of.utility.jar}"/> And define path ao the utility jar application.path.of.utility.jar=/utility/jar/path/application_context.xml

Categories : Java

How to use Spring Beans in a Clojure Application?
(let [context (ClassPathXmlApplicationContext. ...) mybean (.get context "mybean" MyBean)] ...) is the Clojure equivalent of your Java code. ... is whatever you want to do next. Or if you want to return mybean as the value of the whole thing (perhaps this will be wrapped in a function): (let [context (ClassPathXmlApplicationContext. ...)] (.get context "mybean" MyBean)) Note the dot at the end of ClassPathXmlApplicationContext.; that's shorthand for new, as in (new ClassPathXmlApplicationContext ...).

Categories : Java

Java WAR - Load Spring beans from an external JAR
WAR´s appContext.xml and WAR´s web xml are both feasible. If you need to run integration tests based on both localSpringContext.xml and external jar's applicationContext.xml frequently, I recommend the WAR´s appContext.xml approach. Updated1: WAR´s appContext.xml: <import resource="classpath:{classpath}/applicationContext.xml"/> WAR´s web xml: <context-param> <param-name>contextConfigLocation</param-name> <param-value> classpath:localSpringContext.xml classpath:{classpath}/applicationContext.xml </param-value> </context-param> For example, if your applicationContext.xml is under package :com/gmail/hippoom you can get it by classpath:com/gmail/hippoom/applicationContext.xml or classpath*:applicationContext.xml w

Categories : Spring

Spring Java Configuration Overriding Beans
Just a thought, instead of injecting the datasource into the method try the following @Bean(name = "someDaoAnotherDataSource") public SomeDao getSomeDaoAnotherDataSource() throws NamingException { SomeDao dao = new SomeDaoImpl(); dao.setDataSource(otherDataSource()); return dao; } Although both should work. Make sure that the name is correct in your @Resource annotation and instead of (or next to) specifing the name of the bean in the @Bean annotation, rename your method to the same. @Bean(name = "someDaoAnotherDataSource") public SomeDao someDaoAnotherDataSource() throws NamingException { SomeDao dao = new SomeDaoImpl(); dao.setDataSource(otherDataSource()); return dao; } The name is basically an alias whereas the method name is used as the id of the bean.

Categories : Java

Weird validation error in beans.xml Spring CXF
Was able to fix this by adding correct jars, apparently, jboss 7 has it's own off the shelf cxf jars, however the jars I was using with my application was a different version. I just matched the jars and it worked, also exclude jetty in classpath/pom.xml.

Categories : Java

Export beans through HttpInvoker based on beans of certain interface
I doubt U can do it with xml context, but With java it is simple. So In java I would do like that: List<MyServicesInterface> mylist = applicationContext.getBeansOfType(MyServicesInterface.class).values(); ServiceInterface si = applicationContext.getBean(ServiceInterface.class); for(MyServicesInterface mi: mylist){ si.callSomething(mi); } That how I would it in java.

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

Converting JSF Managed beans to CDI Beans
I'm assuming you're on JSF 2.0 or 2.1, in which case you can use MyFaces CODI, or Seam 3, or Omnifaces for @ViewScoped. For JSF 2.2 it's there out of the box. @ManagedProperty becomes @Inject. Yes. No.

Categories : JSF

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

How to find Spring beans.xml
According to this answer, "Generally speaking, you should not put anything into META-INF yourself." Why are you assuming it should be inside META-INF? But, if you want it copied into your ear's META-INF folder, put it under your ejb/src/main/resources/META-INF directory. You may have to create some of those manually.

Categories : Java

How do I get the beans that spring has registered with jmx?
I had tested a sample code as follows // Get the Platform MBean Server MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); // Construct the ObjectName for the MBean we will register ObjectName name = new ObjectName("com.example.mbeans:type=Hello"); // Create the Hello World MBean Hello mbean = new Hello(); // Register the Hello World MBean mbs.registerMBean(mbean, name); Set<ObjectInstance> instances = mbs.queryMBeans(name, null); ObjectInstance instance = (ObjectInstance) instances.toArray()[0]; System.out.println("Class Name:t" + instance.getClassName()); System.out.println("Object Name:t" + instance.getObjectName()); // Wait forever System.out.println("Waiting forever..."); Thread.sleep(Long.MAX_VALUE); Of

Categories : Java

What in the world are Spring beans?
The objects that form the backbone of your application and that are managed by the Spring IoC container are called beans. A bean is an object that is instantiated, assembled, and otherwise managed by a Spring IoC container. These beans are created with the configuration metadata that you supply to the container, for example, in the form of XML definitions. More to learn about beans and scope from SpringSource: When you create a bean definition what you are actually creating is a recipe for creating actual instances of the class defined by that bean definition. The idea that a bean definition is a recipe is important, because it means that, just like a class, you can potentially have many object instances created from a single recipe. You can control not onl

Categories : Java

Spring beans DTD and XMLNS
These lines set up the namespaces for your XML document. Depending on what tags you are using in your XML file, you'll need the namespaces at the top (and references to the correct schemas) in order for the XML to be valid. For example, if you are using the <aop/> tag in your bean definitions, you will need to reference the aop schema at the top of the file: xmlns:aop="http://www.springframework.org/schema/aop" If you aren't using that tag, you don't need that there. For any namespaces you import, make sure you add a reference to the schema in the "xsi:schemaLocation" tag, like this: xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd I would recommend checking out a sample Spring application since it should h

Categories : Java

Undefined beans with Spring MVC
Try and change the type of the autowired property: @Autowired private DynDirectoryServiceInterface You are also missing the <context:annotation-config /> element in the MVC config.

Categories : Java

Spring proxy beans from Interface
The problem was related to ComponentScanning not PostBeanProcessor. ComponentScan is scanning only concrete classes that is why my processor did not work. I had to create a custom importer for interfaces.

Categories : Spring

Spring Beans configuration for Lucene
Using java.io.File imples a file system location, not a classpath entry. Of course, you can always refer to an exploded .war and do something like this (on Tomcat): <value>#{ systemProperties['catalina.base'] }/webapps/myapp.war/WEB-INF/lucene-store</value> However, a much more flexible approach would be to keep the value in an external location (a property file for example): <value>#{ myConfig['lucene-store-root'] }</value> ... or even use java.io.tmpdir system property for testing purposes: <value>#{ systemProperties['java.io.tmpdir'] }/lucene-store</value> You can also switch to a different Directory implementation (example).

Categories : Java

abount the singleton beans of spring
The book is implying that the state of a bean may not be trustworthy at a given point in time due to manipulation of its state by another thread. If multiple threads are accessing the same instance of a bean you cannot be sure of what state changes have occurred on the bean prior to using it. Since Spring uses Singletons by default there is only one instance of a bean. If multiple threads hit the bean at the same time there could be issues with the state of the bean. So your correct that the beans will maintain state, however the state may be unreliable due to modifications from other threads.

Categories : Spring

Can't inject Beans in Spring using annotations and xml
You need to specify your using annotation configuration and component scan for the beans. <context:component-scan base-package="package.with.beans.**" /> <context:annotation-config/> Where package.with.beans.** is the package that contains the bean you are trying to inject the LdapTemplate. You can only inject beans into other beans, since they must be managed by the dependency injection container. So the class your trying to perform the injection in must be a bean and if that bean is established using an annotation, you must tell Spring to component scan to find that bean. For example: package xx.yy.beans; //Used to annotate beans @Component public class Foo{ @Autowired private LdapTemplate ldapTemplate; } Then after importing the context namespace for your Spring

Categories : Java

Spring framework hibernate beans
It looks like you have multiple versions of hibernate on your classpath. The root cause of this error is Caused by: java.lang.VerifyError: class org.hibernate.type.WrappedMaterializedBlobType overrides final method getReturnedClass.()Ljava/lang/Class; My guess is the API changed slightly between versions and your app is loading the wrong version of hibernate (possibly through a transient dependency). It's possible it works on your friend's configuration because the classes just happen to be loaded in the correct order. Verify that are not including multiple versions, and if you are, try to remove the duplicate (or at least force the right version in the dependencyManagement section of your pom).

Categories : Spring

Difference between Spring DOCTYPE and tag
Difference is in formats of documents definitions. First is called DTD, second - XSD. Both are used to describe possible contents of xml document. DTD is older than XSD. XSD is more flexible and powerful than DTD. More differences you can see here.

Categories : Spring

Naming Convention in Spring Beans
Spring beans happen to have "bean" in their name, but they're not really related to Java beans. A property of a Spring bean is the same as a property of any other Java object: something which is optionally readable through a getter and optionally writable through a setter. Whether the object is a spring bean or not doesn't change the definition.

Categories : Spring

Spring ordered list of beans
The @Order annotation is used to specify the order in which AOP advice is executed, it doesn't sort lists. To achieve sorting on your list have your BeanInterface classes implement the Comparable interface and override the compareTo method to specify how the objects should be sorted. Then you can sort the list using Collections.sort(list). Assuming BeanInterface has a method called getSortOrder that returns an Integer object specifying the object's sort order, you could do something like this: @Component public class MyClass implements BeanInterface, Comparable<BeanInterface> { public Integer getSortOrder() { return sortOrder; } public int compareTo(BeanInterface other) { return getSortOrder().compareTo(other.getSortOrder()); } } Then you can so

Categories : Java

Strategy pattern with spring beans
I would use simple Dependency Injection. @Component("burger") public class BurgerStrategy implements MealStrategy { ... } @Component("sausage") public class SausageStrategy implements MealStrategy { ... } Controller Option A: @Resource(name = "burger") MealStrategy burger; @Resource(name = "sausage") MealStrategy sausage; @RequestMapping(method = RequestMethod.POST) public @ResponseBody Something makeMeal(Meat meat) { burger.cookMeal(meat); } Option B: @Autowired BeanFactory bf; @RequestMapping(method = RequestMethod.POST) public @ResponseBody Something makeMeal(Meat meat) { bf.getBean("burger", MealStrategy.class).cookMeal(meat); } You can choose to create JSR-330 qualifiers instead of textual names to catch misspellings during compile time. See also: How to effici

Categories : Java

Jackson Serializers Spring Beans
You can use Jackson HandlerInstantiator to build a bridge between spring and jackson serializer. It is well described here : http://www.runningasroot.com/blog/2012/05/02/autowiring-jackson-deserializers-in-spring/

Categories : Spring

Spring's Javaconfig and Prototyped Beans
I don't think is so much an issue of Spring XML vs Java-base configuration, but one of matching dependency scopes. Since Spring can only do dependency injection on the singleton-scoped bean at creation time, you have to lookup the prototype-scoped bean on demand. Of course the current bean-lookup approach works, but creates a dependency on the ApplicationContext. I can suggest a few other possibilities but the root of the issue is really what is involved in producing a ProtoBean, and what trade-offs should you accept. You could make BeanUser itself prototype-scoped, which would allow you to wire in the ProtoBean as a member. Of course the trade-off is you now have the same problem on the clients of BeanUser, but sometimes that would not be a problem. Another path could be using somethin

Categories : Java

Spring beans getting initialized twice - Spring Integration
Spring MVC Apps generally have 2 contexts; the servlet context and the root context. It's generally good practice to put your "web" beans (@Controllers, views, Http inbound adatpers etc) in the servlet context and all the "business" beans in the root context. Instead of importing your beans, you should put them in the root context using the context loader listener. Beans in the servlet context can get references to beans in the root context, but not vice-versa. The root context is loaded first; the filename doesn't matter but when using wildcards in the contextConfigLocation you need to be careful that the servlet context config is not picked up a second time.

Categories : Spring

Required Multiple beans of same type in Spring
You should qualify your autowired variable to say which one should be injected @Autowired @Qualifier("A1Unmarshaller") private Jaxb2Marshaller A1Unmarshaller; The default autowiring is by type, not by name, so when there is more than one bean of the same type, you have to use the @Qualifier annotation.

Categories : Java

Spring - set of properties files to list of beans
Try something like the following. <bean id="properties1" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="ignoreUnresolvablePlaceholders" value="true"/> <property name="placeholderPrefix" value="${database1."/> <property name="locations"> <list> <value>classpath:database1.properties</value> </list> </property> </bean> <bean id="properties2" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="ignoreUnresolvablePlaceholders" value="false"/> <property name="placeholderPrefix" value="${database2."/> <property name="locations"> <list> <value>classpath:database2.prop

Categories : Spring

Spring creates two beans from one class using annotations
@Autowired is always by type. But you have two Handlers in your configuration. So when you try to autowire the handler class, you have to specify the qualifier. By this spring can resolve which instance to inject. Else, spring throws the error showing NoSuchBeanDefinitionFoundError. Expected one found two. Hope that helps.

Categories : Java

Managing spring beans creation and dictionary
the Spring ApplicationContext can be referred to in this 'dictionary' fashion. that is, you specify to the application context to 'setup' the 'resource beans'. you then map the 'received data' via way of a Map object, that, in turn, holds a reference to the bean. once the data maps to the bean, you can then retrieve the bean and process the received data. here's a brief example here's a resource service interface package de.incompleteco.spring.service; public interface ResourceService { public void processData(Object data); } here's an implementation to process 'TypeA' data package de.incompleteco.spring.service; public class TypeAResourceService implements ResourceService { public void processData(Object data) { //do something for 'type A' data } } here's a 'deleg

Categories : Spring

How to pass parameters dynamically to Spring beans
Please have a look at Constructor injection. However, Spring recommends setter injection to that of constructor. Also, Have a look at IntializingBean and BeanPostProcessor for other life cycle interception of a springbean.

Categories : Java

How to auto run Web Application by Net Beans
Server software is what fetches the webpage and display in the browser, if your server software is not started, it cannot fetch the webpage in your system,you could make the server software start even in the system startup by writing a batch file (.bat) and put it in the startup folder of your C:Windows or making the server software as a service http://tim-sparg.blogspot.in/2010/08/installing-glassfish-as-windows-service.html http://www.coderanch.com/t/512064/java/start-Galssfish-Computer-start

Categories : Jsp

Spring bean creation is failing for beans without an "id" attribute
I'm going to assume you have a <content:component-scan ...> in your config somewhere. This will try to instantiate any @Component annotated classes. @Controller is a @Component so Spring will try to instantiate QueueController using the class default empty constructor. In your case, such a constructor doesn't exist. Therefore it will throw the exception you are seeing. You need to add an empty constructor public QueueController() {} This happens regardless of your bean declaration <bean class="com.xy.web.controllers.QueueController"> <constructor-arg ref="queueServiceImpl"></constructor-arg> </bean> You're going to end up with two QueueController instances. This might not be what you want. As for the behavior you're seeing because of the id: When

Categories : Java

What's the easiest/proper way to wire Spring beans outside a webapp?
Spring provides an IoC container in the form of an ApplicationContext. However, you need to implement your own mechanism for creating the container. But that can be pretty simple public class Start { public static void main(String[] args) { ApplicationContext context = ...// whichever flavor you want // maybe start some threads, possibly managed by the IoC container } } The container itself can either use XML configuration or a programatic one. Read the official documentation on how to do either, here.

Categories : Java

Should I use Spring Session Scoped beans or a cache such as ehcache?
Couple of thoughts on this (disclaimer: I work for terracotta/ehcache...so keep that in mind...but still trying to be unbiased here): 1 - Is there any redundant data in each of the sessions? Anything that could be shared across sessions? If yes, +1 for ehcache to store the shared stuff (because ehcache is optimized for heavy concurrency) 2 - How big are your session objects going to be? And how many concurrent users are you expecting on a steady state basis? (in other words, how much memory are you going to have to dedicate to session storage on your app server?) If session footprint is not that big overall and can fit nicely in your heap without GC issues, then using session should be a fine solution. But the bigger it gets, the larger your java heap will need to be...and the more you

Categories : Spring

Real use case of proptotype scope of spring beans
One popular use of it is to associate separate instance of a bean to each HTTP session. Consider your have a bean class called UserConfig. You can set this bean with prototype scope, and configure such that each new HTTP session has its own UserConfig bean instance. (Spring MVC has its own scope called "session" for this purpose, but the concept is similar) Also the user can change your site configuration, and the changed state is saved on its own instance of the bean (as opposed of altering the global single instance if you set it into singleton scope)

Categories : Spring

multi module maven spring inject beans
You didn't presented your UI class. I suspect that UI is not a Spring managed bean, thus autowiring is off. Or your UI is annotated as Spring bean, but is created with new operator, not taken from Spring context. Well, if you made it as you explained, it must work. No mercy. I made a simple project https://github.com/michaldo/multi-module-vaadin-spring and it works

Categories : Spring

Spring MVC - @Valid on list of beans in REST service
Implement your own validator with org.springframework.validation.beanvalidation.LocalValidatorFactoryBean as a member and call that validator for each item. public class CheckOutValidator implements Validator { private Validator validator; @Override public void validate(Object target, Errors errors) { List request = (List) target; Iterator it = request.iterator() while(it.hasNext()) { MyBean b = it.next(); validator.validate(b, errors); } } //setters and getters }

Categories : Java



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