- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在实现一个使用 Jersey、Hibernate 和 DataSources 的 JAX-RS,但在纠正了很多错误之后,我遇到了一个无法找到解决方案的问题
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408: Unsatisfied dependencies for type ServiceLocator with qualifiers @Default at injection point [UnbackedAnnotatedField] @Inject private org.glassfish.jersey.server.mvc.internal.ViewableMessageBodyWriter.serviceLocator at org.glassfish.jersey.server.mvc.internal.ViewableMessageBodyWriter.serviceLocator(ViewableMessageBodyWriter.java:0)
at org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:362) at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:284) at org.jboss.weld.bootstrap.Validator.validateGeneralBean(Validator.java:137) at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:158) at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:501) at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:61) at org.jboss.weld.bootstrap.ConcurrentValidator$1.doWork(ConcurrentValidator.java:59) at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:62) at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:55) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) at org.jboss.threads.JBossThread.run(JBossThread.java:320)
Controller
我尝试过没有 Stateless、RequestScoped...但没有成功。
import javax.ejb.EJB;
import javax.ejb.LocalBean;
import javax.enterprise.context.RequestScoped;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
@Path("ejb/notificacao")
@Stateless
@LocalBean
@RequestScoped
public class NotificacaoControladorEJB {
SmartJava smartjava = new SmartJava();
@EJB
NotificacaoDAOEJB notificacaoDAO;
@GET
@Produces("application/json; charset=UTF-8")
@Path("/contador/{id}")
public Notificacao contadorGet(@PathParam("id") int id) {
long quantidade;
try {
quantidade = notificacaoDAO.contador(id);
return new Notificacao(quantidade);
} catch(Exception e) {
quantidade = 0;
System.err.println(smartjava.getFullStackTrace(e));
return new Notificacao(quantidade);
}
}
@GET
@Produces("application/json; charset=UTF-8")
@Path("/marcarcomolida/{id}")
public Notificacao marcarcomolida(@PathParam("id") int id) {
try {
Notificacao entidade = notificacaoDAO.GetNotificacao(id);
if(entidade != null) {
entidade.setVisualizado(true);
entidade.setDtvisualizado(new Timestamp(System.currentTimeMillis()));
notificacaoDAO.Alterar(entidade);
return new Notificacao(entidade.getNrseq());
} else {
return new Notificacao();
}
} catch(Exception e) {
System.err.println(smartjava.getFullStackTrace(e));
return null;
}
}
@GET
@Produces("application/json; charset=UTF-8")
@Path("/listar/{id}/{quantidade}")
public List<Notificacao> listar(@PathParam("id") int id, @PathParam("quantidade") int quantidade) {
List<Notificacao> notificacoes = new ArrayList<Notificacao>();
List<Notificacao> listaDeNotificacoes;
try {
if(quantidade < 1) {
listaDeNotificacoes = notificacaoDAO.listarTodosPorUsuarioNrseq(id);
} else {
listaDeNotificacoes = notificacaoDAO.listarQuantidadePorUsuarioNrseq(id, quantidade);
}
if(listaDeNotificacoes != null) {
for (Notificacao notificacao : listaDeNotificacoes) {
Usuario u = construtorUsuario(notificacao.getUseralvo());
notificacoes.add(new Notificacao(notificacao.getNrseq(), notificacao.getTitulo(), notificacao.getConteudo(),
notificacao.getImg(), notificacao.getLink(), notificacao.isAtivo(), notificacao.isVisualizado(),
notificacao.getDtcad(), notificacao.getDtvisualizado(), u));
}
}
return notificacoes;
} catch(Exception e) {
return new ArrayList<Notificacao>();
}
}
@POST
@Consumes("application/json; charset=UTF-8")
@Produces("application/json; charset=UTF-8")
@Path("/cadastrar/um")
public Notificacao cadastrarUm(Notificacao notificacao) {
try {
Notificacao entidade = notificacaoParaEntidade(notificacao, notificacao.getUseralvo());
notificacaoDAO.Salvar(entidade);
return new Notificacao(entidade.getNrseq());
} catch(Exception e) {
System.err.println(smartjava.getFullStackTrace(e));
return new Notificacao();
}
}
public Notificacao cadastrar(Notificacao notificacao) {
try {
Notificacao entidade = notificacaoParaEntidade(notificacao, notificacao.getUseralvo());
notificacaoDAO.Salvar(entidade);
return new Notificacao(entidade.getNrseq());
} catch(Exception e) {
System.err.println(smartjava.getFullStackTrace(e));
return new Notificacao();
}
}
public Notificacao notificacaoParaEntidade(Notificacao notificacao, Usuario usuario) {
Notificacao entidade = new Notificacao();
entidade.setTitulo(notificacao.getTitulo());
entidade.setConteudo(notificacao.getConteudo());
entidade.setImg(notificacao.getImg());
entidade.setDtcad(new Timestamp(System.currentTimeMillis()));
entidade.setUsercad(notificacao.getUsercad());
entidade.setLink(notificacao.getLink());
entidade.setAtivo(true);
entidade.setUseralvo(usuario);
return entidade;
}
private Usuario construtorUsuario(Usuario u) {
try {
return new Usuario(u.getNrseq(), u.getNome(), u.getEmail());
} catch (Exception e) {
return new Usuario();
}
}
}
DAO
import java.util.List;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@Stateless
@LocalBean
public class NotificacaoDAOEJB {
//private EntityManagerFactory entityManagerFactory;
@PersistenceContext
private EntityManager entityManager;
SmartJava sj = new SmartJava();
public Notificacao Salvar(Notificacao notificacao) {
try {
this.entityManager.getTransaction().begin();
this.entityManager.persist(notificacao);
this.entityManager.getTransaction().commit();
} catch (Exception e) {
System.out.println(sj.getFullStackTrace(e));
} finally {
//this.entityManager.close();
}
return notificacao;
}
public void Alterar(Notificacao notificacao){
this.entityManager.getTransaction().begin();
this.entityManager.merge(notificacao);
this.entityManager.getTransaction().commit();
//this.entityManager.close();
}
@SuppressWarnings("unchecked")
public List<Notificacao> Listar(){
return this.entityManager.createQuery("SELECT a FROM Notificacao a ORDER BY a.dtcad").getResultList();
}
public Notificacao GetNotificacao(int nrseq) {
return this.entityManager.find(Notificacao.class, nrseq);
}
@SuppressWarnings("unchecked")
public long contador(int nrsequsuario) {
try {
return (long) this.entityManager.createQuery("SELECT COUNT(a) FROM Notificacao a "
+ "WHERE a.visualizado = false AND a.useralvo.nrseq = :usuario ORDER BY a.dtcad")
.setParameter("usuario", nrsequsuario).getSingleResult();
} catch(Exception e) {
System.err.println(sj.getFullStackTrace(e));
return 0;
}
}
@SuppressWarnings("unchecked")
public List<Notificacao> listarTodosPorUsuarioNrseq(int id) {
try {
return this.entityManager.createQuery("SELECT a FROM Notificacao a "
+ "WHERE a.useralvo.nrseq = :usuario ORDER BY a.dtcad DESC")
.setParameter("usuario", id).getResultList();
} catch(Exception e) {
System.err.println(sj.getFullStackTrace(e));
return null;
}
}
@SuppressWarnings("unchecked")
public List<Notificacao> listarQuantidadePorUsuarioNrseq(int id, int quantidade) {
try {
return this.entityManager.createQuery("SELECT a FROM Notificacao a "
+ "WHERE a.useralvo.nrseq = :usuario ORDER BY a.dtcad DESC")
.setParameter("usuario", id).setMaxResults(quantidade).getResultList();
} catch(Exception e) {
System.err.println(sj.getFullStackTrace(e));
return null;
}
}
}
WEB.XML
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>br.com.souvizinho.controlador</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/webapi/*</url-pattern>
</servlet-mapping>
<!--
<resource-ref>
<description>DB Connection</description>
<res-ref-name>java:/dbsouvizinho</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref> -->
<!-- COMENTAR AO GLASSFISH -->
<!--
<filter>
<filter-name>CorsFilter</filter-name>
<filter-class>org.apache.catalina.filters.CorsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>CorsFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> -->
</web-app>
PERSISTENCE.XML
<!-- JBOS AS 7.11 E WildFly-->
<!-- --> <persistence-unit name="persistence_unit_souvizinho" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:/dbsouvizinho</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform" />
<!-- --> <!-- <property name="hibernate.connection.datasource" value="java:comp/env/jdbc/dbsouvizinho"/> -->
<!-- -->
<!-- <property name="jboss.as.jpa.providerModule" value="org.hibernate:5.2"/> -->
<!-- <property name="hibernate.classloading.use_current_tccl_as_parent" value="false" /> -->
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true"/>
<property name="hibernate.hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit> <!-- -->
POM.XML
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.6</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-mvc-jsp</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.grizzly/grizzly-http-server -->
<dependency>
<groupId>org.glassfish.grizzly</groupId>
<artifactId>grizzly-http-server</artifactId>
<version>2.4.2</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
</dependency>
<!-- TOMCAT -->
<!--
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.1.Final</version>
</dependency> -->
<!-- WILDFLY 11 -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.1.10.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.1.10.Final</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.5.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jboss.logging/jboss-logging -->
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<version>3.3.0.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.37</version>
</dependency>
</dependencies>
最佳答案
为我工作:
删除:
<dependency>
<groupId>org.glassfish.jersey.ext</groupId>
<artifactId>jersey-mvc-jsp</artifactId>
</dependency>
并在我的坚持上加上下面的标签
<class>br.com.souvizinho.modelo.Notificacao</class>
关于java - 焊接-001408 : Unsatisfied dependencies for type ServiceLocator with qualifiers @Default,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49210258/
根据这个answer ,下面的代码应该没有错误地编译: #include namespace { struct A { int i; }; volatile A a{}; static_assert
我了解导入 Data.List。 但是 importqualified Data.List 语句中的 qualified 是什么意思? 最佳答案 合格的导入使导入的实体仅以合格的形式可用,例如 imp
我正在尝试创建一个组件,该组件将接受一个特定的 bean (fasterxml ObjectMapper)。 如果有一个名为 qualifiedObjectMapper 的限定 bean,我想使用那个
我一直在编写以下代码来支持对右值的函数调用,而不必 std::move明确地在返回值上。 struct X { X& do_something() & { // some co
我正在尝试使用 GCC 编译器编译以下代码 class Class { public: uInt16 temp; const uInt32 function() const; } inline
我试图理解为什么我的编译器警告我有关此代码: static const char *const _menuMain_Strings_1[] __ATTR_PROGMEM__ = { _menuMai
我正在尝试将 Spring 4.x.x 迁移到 Spring boot,它依赖于外部 spring 2.5 jar 中的类。我已经进行了所有 Autowiring 更改,下面是我的应用程序类 @Spr
我从 eclipse git 中查看了最新的源代码:git://git.eclipse.org/gitroot/platform/eclipse.platform.releng.aggregator.
我发现许多门户网站都解释了类似的问题。但我想这是独特的情况。我在 spring mvc 应用程序中遇到错误。 org.springframework.beans.factory.Unsatisfied
我有下面的代码: package far.botshop.backend.controller; /** */ import java.util.logging.Logger; import far
我有 3 个数据源,设置如下: @Configuration @Component public class DataSourceConfig { @Bean("foo") @Conf
如何添加限定符来区分这两个 bean?我知道我需要使用 @Qualifier 注释,但我不确定如何将它添加到 bean 中,然后如何引用适当的 bean 创建 Autowiring 对象。 @Conf
@Override @Autowired(required = true) @Qualifier("hibernateCriteriaBuilder") public void setCriteria
我有 Circle 类: public class Circle { @Autowired @Qualifier("pointA") private Point center;
我在 Java Spring 环境中工作,并且在让 @Qualifier 工作时遇到了问题。我们项目的其他部分正在使用 @Inject 获取一个 bean,但我需要同一个 bean 的两个版本,看起来
“qualifier”的含义是什么?“qualifier”和“keyword”之间的区别是什么? 对于C语言中的volatile限定词,我们可以说volatile是一个关键字,那么“qualifier
我有一个简单的宏来设置一些常见的标题和格式: Dim colString(1 To 17, 1 To 2) As String Dim i As Integer colString(1, 1) = "
我正在将 Teradata 转换为 Hive(版本 0.10.0)。 Teradata 查询: QUALIFY ROW_NUMBER() OVER (PARTITION BY ADJSTMNT,SRC
我是在 PHP 中使用命名空间的新手,它们看起来很简单。然而,当我在一个包含类、接口(interface)和闭包的大文件的顶部添加一个命名空间时,代码完全停止工作。显然,某些元素没有正确限定。 例如:
我正在尝试使用属性占位符作为@Qualifier 的属性,如下所示: @Autowired @Qualifier("${beanName}") private MyBean myBean; 但是,这不
我是一名优秀的程序员,十分优秀!