4

I have a parametrized abstract class with one parametrized constructor:

public abstract class BasicEntidadController<T extends Entidad> implements Serializable {

     public BasicEntidadController(EntidadBean<T> entidadSessionBean) {....}
     // other methods
}

and a child class extending it:

@SessionScoped
@Named
public class TiendaController extends BasicEntidadController<Tienda> implements Serializable {...}

and WELD reports an error telling me that "BasicEntidadController" is not proxyable....

org.jboss.weld.exceptions.UnproxyableResolutionException: WELD-001435 Normal scoped bean class org.wgualla.sandbox.entity.BasicEntidadController is not proxyable because it has no no-args constructor - Managed Bean [class org.wgualla.sandbox.tienda.TiendaController] with qualifiers [@Any @Default @Named].

Why WELD is trying to create a proxy of this abstract/no-bean class???

Must I do all classes, in inheritance tree, proxyables if I want to inject/use in EL expresion just the last child in the tree?

Thanks in advance.

Ondra Žižka
  • 43,948
  • 41
  • 217
  • 277
wgualla
  • 61
  • 6
  • The exception message mentions - *Managed Bean [class org.wgualla.sandbox.tienda.TiendaController]* and the complaint is - *has no no-args constructor*. May be the message is not so straight forward but try adding a no-arg constructor. – Bhesh Gurung Jun 27 '13 at 19:17
  • Yes, thank you. This is the easy way. I could want to know why weld is trying to create a proxy if this class is abstract and never will be instanciated. – wgualla Jun 27 '13 at 19:32
  • 1
    because anything that is eligible for injection needs to follow the requirements. It's one of those gotchas around CDI and managed beans. – John Ament Jun 27 '13 at 23:10
  • this means that I can't have a class that does not meet the requirements of the CDI within the entire project? – wgualla Jun 29 '13 at 06:58
  • Within the class hierarchy, no. You could veto that underlying class as an alternative. – John Ament Jun 29 '13 at 17:39

1 Answers1

2

By definition a java bean has "The class must have a public default constructor (with no arguments)."

See http://en.wikipedia.org/wiki/JavaBeans#JavaBeans_API

I would suggest that you change your constructor to

public BasicEntidadController() {....}
     // other methods

and then add a setter method

setEntidadSessionBean(EntidadBean<T> entidadSessionBean)

Or even better - read about dependancy injection. You can then use something like

@Autowired
EntidadBean<T> entidadSessionBean;

See http://www.vogella.com/articles/SpringDependencyInjection/

Hope this helps

sashok_bg
  • 2,436
  • 1
  • 22
  • 33