我的问题是关于 Spring 数据生成查询的方式。
我有两个实体:消息,发件人
@Entity
public class Message extends BaseEntity {
@ManyToOne
protected Account sender;
}
Run Code Online (Sandbox Code Playgroud)
我有一个电话
messageDao.findBySenderId(Long id)
Run Code Online (Sandbox Code Playgroud)
结果是在两个表left outer join之间查询两个表中的所有列,但我的期望只是从消息表中选择where sender_id =传递的值。
那么有没有办法强制只选择第一个消息实体而不是加入另一个消息实体?我想要在 where 子句中使用 findBy 而不是自定义 @Query 的简单条件
我有一个在Kubernetes集群中的Docker容器中运行的webapp。该应用程序具有一个我想定期调用的端点。该应用程序在多个节点/吊舱中运行,重要的是只有一个节点执行端点发起的任务。我看过Kubernetes Cron Jobs,但没有找到有关从Kubernetes Cron Job调用端点的任何文档。有人有解决这个问题的建议吗?在只有一个节点执行任务的群集中,您如何处理调度?
我试图理解为什么我不能自动装配类库,但我可以在相同的包中自动装配一个接口存储库以进行相同的测试.当我启动应用程序时,相同的存储库按预期工作.
一,错误:
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.app.person.repository.PersonRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultPersonbleBeanFactory.raiseNoMatchingBeanFound(DefaultPersonbleBeanFactory.java:1493)
at org.springframework.beans.factory.support.DefaultPersonbleBeanFactory.doResolveDependency(DefaultPersonbleBeanFactory.java:1104)
at org.springframework.beans.factory.support.DefaultPersonbleBeanFactory.resolveDependency(DefaultPersonbleBeanFactory.java:1066)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585)
... 28 more
Run Code Online (Sandbox Code Playgroud)
我有一个非常简单的例子.考试:
@RunWith(SpringRunner.class)
@DataJpaTest
public class PersonRepositoryTest {
@Autowired
private PersonRepository personRepository; // fail...
@Autowired
private PersonCrudRepository personCrudRepository; // works!
@Test
public void findOne() {
}
}
Run Code Online (Sandbox Code Playgroud)
存储库类:
@Repository
public class PersonRepository {
//code
}
Run Code Online (Sandbox Code Playgroud)
存储库界面:
@Repository
public interface PersonCrudRepository extends …Run Code Online (Sandbox Code Playgroud) 我使用Flux,React和我有组件简单和消息:
jqXHR.done().简单有一个更改侦听器等待调度结果.如果结果为null,我想使用我的Messages组件显示错误,所以我打电话给我MessagesAction.addError('My result is null').当我收到null结果并立即调用MessagesAction.addErrorSimple组件内部时,会出现问题.事实上,我知道这可能会导致"在调度中间发送 "错误,但我不知道如何重构此代码以显示使用Flux的错误消息.
免责声明1:我无法使用setTimeout函数来解决此问题.这不是正确的解决方案.
免责声明2:该Simple组件代表app中的任何其他组件,它也将使用Messages组件显示消息.
简单代码:
findUser: function (value) {
UserAction.find(value);
},
componentDidMount: function () {
UserStore.addChangeListener(this.updateUser);
},
updateUser: function(){
var user = UserStore.getUser();
if (user == null){
MessagesAction.addError('My result is null!'); //here occur the error!
} else {
//set my user with setState
}
},
Run Code Online (Sandbox Code Playgroud)
消息代码:
componentDidMount: function () {
MessagesStore.addChangeListener(this.addMessage);
},
addMessage: function () {
this.setState({
messages: MensagensStore.getMessages() …Run Code Online (Sandbox Code Playgroud) 我正在试图弄清楚我对API项目架构的选择.
我想使用JAX-RS 1.0版创建一个API.此API从更大,更旧,更复杂的应用程序中使用远程EJB(EJB 3.0).我正在使用Java 6.
到目前为止,我可以做到这一点并且有效.但我对解决方案不满意.看我的包裹配置.我的问题在代码后面描述:
/api/
/com.organization.api.v1.rs -> Rest Services with the JAX-RS annotations
/com.organization.api.v1.services -> Service classes used by Rest Services. Basically, they only have the logic to transform the DTOs objects from Remote EJBs in JSON. This is separated by API version, because the JSON can be different in each version.
/com.organization.api.v1.vo -> View Objects returned by the Rest Services. They will be transformed in JSON using Gson.
/com.organization.api.services -> Service classes used by versioned Services.
Here …Run Code Online (Sandbox Code Playgroud) 我使用Resteasy 创建了一个项目来测试Google Guice在我的Jax-rs资源中提供的依赖注入.
我的意图是:
@ApplicationPath对我的API版本使用multiple .在每个用@ApplicationPathI 注释的类中,为特定版本加载一组类.@Inject(来自Google Guice)在他的构造函数中注入一些服务.我创建了两个带有注释的类@ApplicationPath:ApplicationV1RS和ApplicationV2RS.在这两个中我添加了相同的资源类(UserResource和HelloResource),仅用于我的测试.
我的模块配置如下:
public class HelloModule implements Module
{
public void configure(final Binder binder)
{
binder.bind(IGreeterService.class).to(GreeterService.class);
binder.bind(IUserService.class).to(UserService.class);
}
}
Run Code Online (Sandbox Code Playgroud)
当我打电话http://localhost:9095/v1/hello/world或http://localhost:9095/v2/hello/world,我收到同样的错误:
java.lang.RuntimeException: RESTEASY003190: Could not find constructor
for class: org.jboss.resteasy.examples.guice.hello.HelloResource
Run Code Online (Sandbox Code Playgroud)
好吧,正如我所料,这不起作用.对于我来说,使用construtor实例化资源类并不是"聪明"的.
但我找不到办法.说实话,我真的很困惑Google Guice,Jetty和Resteasy在这种情况下如何互相玩耍.
如果我放弃使用的想法@ApplicationPath,我的资源与Google Guice一起配置我HelloModule这样:
public class HelloModule implements Module
{
public void configure(final Binder binder)
{
binder.bind(HelloResource.class);
binder.bind(IGreeterService.class).to(GreeterService.class); …Run Code Online (Sandbox Code Playgroud) 我想知道是否可以自定义以下授权错误:
{
"error": "unauthorized",
"error_description": "Full authentication is required to access this resource"
}
Run Code Online (Sandbox Code Playgroud)
当用户请求没有权限时,我得到了它。我想将其自定义为与Spring Boot错误非常相似:
{
"timestamp":1445441285803,
"status":401,
"error":"Unauthorized",
"message":"Bad credentials",
"path":"/oauth/token"
}
Run Code Online (Sandbox Code Playgroud)
有可能吗
非常感谢。
java security spring-security spring-boot spring-security-oauth2
我有简单的 JPA 查询
Query query = getEntityManager().createQuery("SELECT pn FROM ProductsNames pn"
+ " WHERE pn.languages = :language"
+ " ORDER BY pn.products.id ASC");
query.setParameter("language", language);
return query.getResultList();
Run Code Online (Sandbox Code Playgroud)
如何检查这些方法的结果是从缓存返回对象列表还是直接从数据库返回对象列表?
在persistence.xml中,我设置了以下参数:
<property name="eclipselink.logging.level.sql" value="FINE"/>
Run Code Online (Sandbox Code Playgroud)
所以在服务器的输出上我可以监控执行的查询(但我不确定 - 如果查询在输出上可见,这意味着查询已发送到数据库,或者意味着查询已发送到 entityManager 和 entityManager 决定使用缓存和后来将查询发送到数据库)。
那么我如何区分对象的结果来自:
我将不胜感激。
我正在尝试设置Jboss服务器"客户端"(版本5.1.0)以使用来自另一个Jboss服务器(10.90.0.91)的远程EJB,但我不能使用Jboss客户端上的jndi.properties文件来执行此操作.
我可以在客户端上使用这个简单的代码获取远程EJB:
InitialContext ctx = null;
try {
Hashtable<String, String> jndiProps = new Hashtable<String, String>();
jndiProps.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
jndiProps.put(InitialContext.PROVIDER_URL, "jnp://10.90.0.91:1099");
ctx = new InitialContext(jndiProps);
return ctx.lookup(jndiName);
} catch (NamingException e) {
throw new RuntimeException(e);
}
Run Code Online (Sandbox Code Playgroud)
这很好用.
现在我想用这个属性设置Jboss客户端.但是,如果我编辑本地化的现有jndi.properties文件server/{application}/conf/:
# DO NOT EDIT THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING
#
java.naming.factory.initial=org.jboss.iiop.naming.ORBInitialContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
Run Code Online (Sandbox Code Playgroud)
至:
# DO NOT EDIT THIS FILE UNLESS YOU KNOW WHAT YOU ARE DOING
#
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.provider.url=jnp://10.90.0.91:1099
Run Code Online (Sandbox Code Playgroud)
当我启动Jboss客户端时,我收到一些错误(显然,我不知道我在做什么:)):
2016-08-19 10:17:41,645 ERROR [org.jboss.kernel.plugins.dependency.AbstractKernelController] (main) Error installing to …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 来测试我的 Rest Controller 的 Rest 合约@WebMvcTest,例如:
@RunWith(SpringRunner.class)
@WebMvcTest(MyController.class)
class MyControllerTest {
Run Code Online (Sandbox Code Playgroud)
我正在测试的方法仅使用 MyFirstService,但在类内部还有另外两个服务(MySecondService 和 MyThirdService)由另外两个方法使用。
问题是使用@MockBean. 测试类在决赛中似乎是这样的:
@RunWith(SpringRunner.class)
@WebMvcTest(MyController.class)
class MyControllerTest {
@MockBean
private MyFirstService s1; // internal method mocked for the test
@MockBean
private MySecondService s2; //never used
@MockBean
private MyThirdService s3; //never used
...
@Test
public void testMethod() [
// mock s1
// calls rest controller method
MvcResult mvcResult = mvc.perform(post("/products")
.header("Content-Type", "application/json")
.content(json))
.andExpect(status().isCreated())
.andReturn();
}
}
Run Code Online (Sandbox Code Playgroud)
我认为这个解决方案对于这些注释并不优雅......声明的 s2 和 s3 似乎没有被阅读代码的人使用。注入到 …
java ×6
spring ×3
ejb-3.0 ×2
jax-rs ×2
spring-boot ×2
architecture ×1
caching ×1
cron ×1
eclipselink ×1
ejb ×1
flux ×1
guice ×1
jboss ×1
jboss5.x ×1
jpa ×1
jpql ×1
kubernetes ×1
mocking ×1
reactjs ×1
resteasy ×1
security ×1
spring-data ×1
testing ×1