Announcement Announcement Module
Collapse
No announcement yet.
puzzling "bean name must not be empty" error Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • puzzling "bean name must not be empty" error

    hello, i was wondering if anyone could help me with this puzzling error. i'm defining a bean in a properties file and a method reads in the properties file like this:
    Code:
    beanReader.loadBeanDefinitions(resource, "config");
    param.setLovResolver((LOVResolver)beanFactory.getBean("config"));
    the resource is loaded from following properties file:
    Code:
    config.(class)=sandbox.domain.Config
    config.valueClass=java.lang.String
    now the error:
    Code:
    java.lang.IllegalArgumentException: Bean name must not be empty
    	at org.springframework.util.Assert.hasText(Assert.java:169)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.registerBeanDefinition(DefaultListableBeanFactory.java:310)
    	at org.springframework.beans.factory.support.PropertiesBeanDefinitionReader.registerBeanDefinition(PropertiesBeanDefinitionReader.java:468)
    	at org.springframework.beans.factory.support.PropertiesBeanDefinitionReader.registerBeanDefinitions(PropertiesBeanDefinitionReader.java:373)
    	at org.springframework.beans.factory.support.PropertiesBeanDefinitionReader.loadBeanDefinitions(PropertiesBeanDefinitionReader.java:257)
    	at org.springframework.beans.factory.support.PropertiesBeanDefinitionReader.loadBeanDefinitions(PropertiesBeanDefinitionReader.java:221)
    	at sandbox.service.ReportService.getParameters(ReportService.java:89)
    	at sandbox.web.ConfigureReportFormController.formBackingObject(ConfigureReportFormController.java:43)
    	at org.springframework.web.servlet.mvc.AbstractFormController.getErrorsForNewForm(AbstractFormController.java:341)
    	at org.springframework.web.servlet.mvc.AbstractFormController.showNewForm(AbstractFormController.java:322)
    	at org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:262)
    	at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
    	at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
    	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:723)
    	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:663)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:394)
    	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:348)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
    	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
    	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
    	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
    	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
    	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
    	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
    	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
    	at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
    	at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
    	at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    	at java.lang.Thread.run(Unknown Source)
    as for versions, i'm using spring 1.2.8, java 1.4, tomcat 5.5, and other libraries are dependencies from spring 1.2.8 release.

    i've had another app in spring rich client do extremely similar thing and that worked... please help me out.

  • #2
    try

    Code:
    beanReader.loadBeanDefinitions(resource);
    param.setLovResolver((LOVResolver)beanFactory.getBean("config"));
    The properties file is parsed with this method (from PropertiesBeanDefinitionReader).
    Code:
    	/**
    	 * Register bean definitions contained in a Map.
    	 * Ignore ineligible properties.
    	 * @param map Map name -> property (String or Object). Property values
    	 * will be strings if coming from a Properties file etc. Property names
    	 * (keys) <b>must</b> be strings. Class keys must be Strings.
    	 * @param prefix match or filter within the keys in the map: e.g. 'beans.'
    	 * (can be empty or <code>null</code>)
    	 * @param resourceDescription description of the resource that the Map came from
    	 * (for logging purposes)
    	 * @return the number of bean definitions found
    	 * @throws BeansException in case of loading or parsing errors
    	 * @see #registerBeanDefinitions(Map, String)
    	 */
    	public int registerBeanDefinitions(Map map, String prefix, String resourceDescription)
    			throws BeansException {
    
    		if (prefix == null) {
    			prefix = "";
    		}
    		int beanCount = 0;
    
    		for (Iterator it = map.keySet().iterator(); it.hasNext();) {
    			Object key = it.next();
    			if (!(key instanceof String)) {
    				throw new IllegalArgumentException("Illegal key [" + key + "]: only Strings allowed");
    			}
    			String keyString = (String) key;
    			if (keyString.startsWith(prefix)) {
    				// Key is of form: prefix<name>.property
    				String nameAndProperty = keyString.substring(prefix.length());
    				// Find dot before property name, ignoring dots in property keys.
    				int sepIdx = -1;
    				int propKeyIdx = nameAndProperty.indexOf(PropertyAccessor.PROPERTY_KEY_PREFIX);
    				if (propKeyIdx != -1) {
    					sepIdx = nameAndProperty.lastIndexOf(SEPARATOR, propKeyIdx);
    				}
    				else {
    					sepIdx = nameAndProperty.lastIndexOf(SEPARATOR);
    				}
    				if (sepIdx != -1) {
    					String beanName = nameAndProperty.substring(0, sepIdx);
    					if (logger.isDebugEnabled()) {
    						logger.debug("Found bean name '" + beanName + "'");
    					}
    					if (!getBeanFactory().containsBeanDefinition(beanName)) {
    						// If we haven't already registered it...
    						registerBeanDefinition(beanName, map, prefix + beanName, resourceDescription);
    						++beanCount;
    					}
    				}
    				else {
    					// Ignore it: It wasn't a valid bean name and property,
    					// although it did start with the required prefix.
    					if (logger.isDebugEnabled()) {
    						logger.debug("Invalid bean name and property [" + nameAndProperty + "]");
    					}
    				}
    			}
    		}
    
    		return beanCount;
    	}
    So it is checking for properties starting with prefix, stripping the prefix, letting only the .(class) reside, which leaves a bean definition without a beanname.

    Comment


    • #3
      thanks for the quick response. it worked! although, i've gotta wonder, why the same lines of code worked in my spring rich client app and not here. perhaps the slight version difference... anyway thank you!

      Comment

      Working...
      X