Solucionado (ver solução)
Solucionado
(ver solução)
3
respostas

Upload imagens Vraptor 4

Estou tenatando criar uma classe de imagens para fazer upload de imagens.

Configurações: Tomcat 8, Vraptor4 e Hibernate.

1 - Criei uma classe de imagens, um construtor recendo servlet context e method de upload.2 - Add todas as dependências exigidas.

Na controller da minha entidade criei a seguinte variável :

@Inject private Imagens imagens;

Aparentemente tudo certo, porém o Vraptor tem apresentado o seguinte erro:

org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:ifeventos' did not find a matching property.
Jan 29, 2017 6:17:31 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server version:        Apache Tomcat/8.0.26
Jan 29, 2017 6:17:31 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server built:          Aug 18 2015 11:38:37 UTC
Jan 29, 2017 6:17:31 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Server number:         8.0.26.0
Jan 29, 2017 6:17:31 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Name:               Windows 10
Jan 29, 2017 6:17:31 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: OS Version:            10.0
Jan 29, 2017 6:17:31 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Architecture:          amd64
Jan 29, 2017 6:17:31 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Java Home:             C:\Program Files\Java\jre1.8.0_102
Jan 29, 2017 6:17:31 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Version:           1.8.0_102-b14
Jan 29, 2017 6:17:31 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: JVM Vendor:            Oracle Corporation
Jan 29, 2017 6:17:31 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_BASE:         C:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Jan 29, 2017 6:17:31 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: CATALINA_HOME:         C:\Program Files\Apache Software Foundation\Tomcat 8.0
Jan 29, 2017 6:17:31 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.base=C:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0
Jan 29, 2017 6:17:31 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcatalina.home=C:\Program Files\Apache Software Foundation\Tomcat 8.0
Jan 29, 2017 6:17:31 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dwtp.deploy=C:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps
Jan 29, 2017 6:17:31 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.endorsed.dirs=C:\Program Files\Apache Software Foundation\Tomcat 8.0\endorsed
Jan 29, 2017 6:17:31 PM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dfile.encoding=Cp1252
Jan 29, 2017 6:17:31 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jre1.8.0_102\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS;C:/Program Files/Java/jre1.8.0_102/bin/server;C:/Program Files/Java/jre1.8.0_102/bin;C:/Program Files/Java/jre1.8.0_102/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\system32\config\systemprofile\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files\Java\jdk1.8.0_102\bin\;C:\apache-maven-3.3.9\bin\;C:\Program Files\MySQL\MySQL Utilities 1.6\;C:\Program Files\nodejs\;C:\Program Files\Git\cmd;C:\Users\notgnihsaw-pc\AppData\Roaming\npm;C:\Users\notgnihsaw-pc\AppData\Local\Microsoft\WindowsApps;;C:\Program Files (x86)\Microsoft VS Code\bin;C:\Users\notgnihsaw-pc\Documents\Eclipse luna;;.
Jan 29, 2017 6:17:31 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-nio-8080"]
Jan 29, 2017 6:17:31 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Jan 29, 2017 6:17:31 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-nio-8009"]
Jan 29, 2017 6:17:31 PM org.apache.tomcat.util.net.NioSelectorPool getSharedSelector
INFO: Using a shared selector for servlet write/read
Jan 29, 2017 6:17:31 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 966 ms
Jan 29, 2017 6:17:31 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jan 29, 2017 6:17:31 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/8.0.26
Jan 29, 2017 6:17:34 PM org.apache.jasper.servlet.TldScanner scanJars
INFO: At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
Jan 29, 2017 6:17:34 PM org.jboss.weld.bootstrap.WeldStartup <clinit>
INFO: WELD-000900: 2.1.2 (Final)
Jan 29, 2017 6:17:35 PM org.jboss.weld.bootstrap.WeldStartup startContainer
INFO: WELD-000101: Transactional services not available. Injection of @Inject UserTransaction not available. Transactional observers will be invoked synchronously.
Jan 29, 2017 6:17:35 PM org.hibernate.validator.internal.util.Version <clinit>
INFO: HV000001: Hibernate Validator 5.1.1.Final
Jan 29, 2017 6:17:42 PM org.jboss.weld.environment.tomcat7.Tomcat7Container initialize
INFO: Tomcat 7+ detected, CDI injection will be available in Servlets and Filters. Injection into Listeners is not supported
Jan 29, 2017 6:17:44 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class org.jboss.weld.environment.servlet.Listener
org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type Imagens with qualifiers @Default
  at injection point [BackedAnnotatedParameter] Parameter 2 of [BackedAnnotatedConstructor] @Inject public br.com.ifg.ifeventos.controller.NoticiaController(Result, Imagens)
  at br.com.ifg.ifeventos.controller.NoticiaController.<init>(NoticiaController.java:0)

    at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:368)
    at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:289)
    at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:135)
    at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:166)
    at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:514)
    at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:68)
    at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:66)
    at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:60)
    at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:53)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

Jan 29, 2017 6:17:44 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: One or more listeners failed to start. Full details will be found in the appropriate container log file
Jan 29, 2017 6:17:44 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/ifeventos] startup failed due to previous errors
Jan 29, 2017 6:17:44 PM org.apache.catalina.core.StandardContext listenerStop
SEVERE: Exception sending context destroyed event to listener instance of class org.jboss.weld.environment.servlet.Listener
java.lang.NullPointerException
    at org.jboss.weld.servlet.WeldInitialListener.contextDestroyed(WeldInitialListener.java:120)
    at org.jboss.weld.servlet.api.helpers.ForwardingServletListener.contextDestroyed(ForwardingServletListener.java:30)
    at org.jboss.weld.environment.servlet.Listener.contextDestroyed(Listener.java:85)
    at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4776)
    at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5390)
    at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1408)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1398)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

Jan 29, 2017 6:17:44 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-nio-8080"]
Jan 29, 2017 6:17:44 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-nio-8009"]
Jan 29, 2017 6:17:44 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 12470 ms
3 respostas

A classe Imagens ta anotado com algum escopo? Como está o seu beans.xml? Esse erro tem a ver com o cdi, não necessariamente com o vraptor.

Sim, com @RequestScoped

beans.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
                            http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
    version="1.1" bean-discovery-mode="all">

</beans>
solução!

Alberto,

Me desculpe, voltei na documentação e percebi que faltava isso:

O CDI exige que cada classe possua o construtor padrão (sem argumentos). Sendo assim você deverá adicionar o construtor padrão em todos os componentes. E o construtor onde serão injetados os componentes deve possuir a anotação @Inject.

Obrigado.