Tag: spring

解释这个Spring MVC Controller的行为

我有这堂课: @Component @Scope(“session”) @Entity @Table(name = “users”) public class User { @Id @GeneratedValue @GenericGenerator(name = “incremental”, strategy = “increment”) private Long userID; @Column(nullable = false) private String username; @Column(nullable = false) private String email; @Column(nullable = false) private String password; // getters and setters } 而这个控制器: @Controller @SessionAttributes(“user”) @Scope(“request”) public class UserCreationWizard { @Autowired private […]

Spring Transactional注释,隔离不适用于READ_UNCOMMITTED

我在Java中有一个方法,它由spring Transactional注释包装。 我里面有2个操作,一个是delete ,另一个是insert 。 我的插入语句必须依赖于第一个操作(即delete ),但是由于第一个操作尚未提交,我的插入失败(唯一约束)。 但有趣的是,通常在同一个事务中,我应该能够在同一个事务中读取/查看未经授权的操作(我的旧专有框架能够做到这一点),但这不适用于我的场景,第二个插入仍然失败,因为它看到数据尚未删除。 我尝试使用隔离READ_UNCOMMITTED ,但它不起作用。 我必须将这两个操作放在同一个事务中,因为任何一个失败都应该回滚两个操作,我不能提交第一个操作然后继续第二个操作。 我怎么能在Spring框架中做到这一点?

保护基于Spring消息传递的websocket服务

我现在正在研究这个问题已有3个星期没有真正的解决方案,我真的希望你能帮助我。 一点项目背景: 使用基于JavaScript / PHP的客户端的Webapp通过SocksJS发送消息并向“门”发送消息 门是用Java / Spring编写的,使用@SendTo和@MessageMapping来发送和接收消息 来自门的消息被发送到RabbitMQ并通过“messageBrokerRegistry.enableStompBrokerRelay”返回给客户端 到目前为止它的工作原理,发送的消息都会回来。 现在是高级安全部分: 消息应该通过包含用户和东西的cookie来保护…… 据我所知,WebSockets本身并不支持安全性。 您必须像使用BASIC auth或类似的“常用”webapp一样保护您的webapp。 所以我添加了一个servletfilter,其中包含一个扩展GenericFilterBean的类。 如果用户发送了正确的cookie页面加载,否则他会收到403错误。 现在出现了问题: 由于@SendTo向所有订阅者发送消息而@SendToUser似乎只将其发送到一个会话,因此我倾向于使用@SendToUser。 但似乎无法选择要创建的rabbitMQ队列。 我想要一些像“/ myqueue-user-123”。 @SendToUser无法做到这一点,因为生成的队列是随机的,并且基于SessionID,我无法覆盖。 所以我尝试过(我尝试除了拦截器,事件等之外的其他东西),使用@SendTo没有值,以便客户端可以决定它必须发送到的队列。 我现在需要的是评估cookie中的用户与“/ myqueue / user-123”相关联。 如果不是,请不要向他发送消息。 阻止他订阅。 断开他,无论如何。 但在我看来,你绝对不能 – 阻止发送消息,只是“拦截”以记录它们而不是改变 – 断开websocket因为它自动尝试重新连接 – 抛出exception,因为订阅仍然继续(事件只是事件,不是要干涉的东西)。 我会非常感谢任何建议或提示。 因为我完全被困在这里……

使用Spring HibernateDaoSupport进行延迟加载?

问候我正在使用Spring + Hibernate开发一个非Web应用程序。 我的问题是HibernateDaoSupport如何处理延迟加载,因为在调用DAO之后,Session被关闭了。 看看下面的伪代码: DAO就像: CommonDao extends HibernateDaoSupport{ Family getFamilyById(String id); SubFamily getSubFamily(String familyid,String subfamilyid); } 域模型如下: Family{ private List subfamiles; public List getSubFamiles(); } SubFamily{ private Family family; public Family getFamily(); } 在应用程序中,我从app-context获取DAO并希望执行以下操作。这可能与延迟加载有关,因为AFAIK在每个方法(getFamilyById(),getSubFamily())之后关闭会话。 CommonDAO dao=//get bean from application context; Family famA=dao.getFamilyById(familyid); // //Do some stuff List childrenA=fam.getSubFamiles(); SubFamily asubfamily=dao.getSubFamily(id,subfamilyid); // //Do some other […]

spring框架卡在调试日志级别上

我正在尝试通过log4j.xml配置spring框架日志记录级别。 我的文件看起来像这样: <!– –> <!– –> <!– –> 但是,spring正在记录调试信息,这里是catalina.out的示例: 15:46:03.535 [http-bio-8080-exec-3] DEBUG osswumAntPathRequestMatcher – Checking match of request : ‘/oauth/token’; against ‘/oauth/cache_approvals’ 15:46:03.536 [http-bio-8080-exec-3] DEBUG osswumAntPathRequestMatcher – Checking match of request : ‘/oauth/token’; against ‘/oauth/uncache_approvals’ 15:46:03.536 [http-bio-8080-exec-3] DEBUG osswumAntPathRequestMatcher – Checking match of request : ‘/oauth/token’; against ‘/oauth/token’ 15:46:03.536 [http-bio-8080-exec-3] DEBUG ossecurity.web.FilterChainProxy – /oauth/token?grant_type=password&client_id=my-trusted-client-with-secret&client_secret=somesecret&username=seema&password=jrd@123456 at […]

Spring @Scheduler正在执行两次。 我正在使用spring security,如果我删除上下文参数spring安全性不起作用

我在我的应用程序中使用spring Scheduler和spring security。 如果spring-servlet.xml文件在上下文参数中分配,则spring安全工作正常,但Spring Scheduler执行两次。 安全的context.xml <!– –> 为spring-servlet.xml com.joseph.model org.hibernate.cfg.AnnotationConfiguration ${jdbc.dialect} true 调度程序类 package com.joseph.cronJob; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; @Service public class SampleCronJobImpl implements SampleCronJob { private static int count=0; @Override @Scheduled(cron = “0 */1 * * * *”) public void testSchedulerfunction() { count++; System.out.println(“scheduler fuction call count: “+count); } } web.xml中 CRUDWebAppMavenizedold log4jConfigLocation […]

Spring XML消息源,bean XML中的getMessage?

我已经设置了这样的资源: locale\\messages 我的房产文件: battle.name=TestBattle 我想在使用bean时到达文本“TestBattle”: 我想在此行中的propertyFile中重新发送消息 有没有办法做到这一点,而无需使用 getMessage(“battle.name”,… java中的代码?

使用spring mvc进行静态内容渲染

我是新手,我正在尝试它。 我有一个jsp文件,其中包括css和图像如下 现在我有一个url路径作为/localhost/myapp/test/tst ,它被映射到一个控制器,然后转发它来查看jsp view.jsp出现了 /web-inf/jsp/view.jsp 但是当命中路径/localhost/myapp/test/tst ,css和images路径被解析为 /localhost/myapp/test/tst/css/style.css 我希望它来自/localhost/myapp/css/style.css css和html存在于webapp的根目录中 我如何跟随我的春季配置

使用TransactionManager使用Spring JmsTemplate编写消息

使用Spring-JMS,可以通过DefaultMessageListenerContainer在外部事务上下文中接收消息。 但是, 编写消息的唯一记录方法是通过JmsTemplate.send(…) ,我无法看到如何强制使用给定的TransactionManager 。 谁能指出我正确的方向? 更多信息:确保事务管理器可用( WebSphereUowTransactionManager ),对Oracle AQjmsFactory.getQueueConnectionFactory(dataSource)使用JmsTemplate.write导致: org.springframework.jms.UncategorizedJmsException: Uncategorized exception occured during JMS processing; nested exception is oracle.jms.AQjmsException: could not use local transaction commit in a global transaction at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:316) at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:168) at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:469) at org.springframework.jms.core.JmsTemplate.send(JmsTemplate.java:534) Caused by: oracle.jms.AQjmsException: could not use local transaction commit in a global transaction at oracle.jms.AQjmsSession.commitNoCheck(AQjmsSession.java:1053) at […]

Tomcat:PreResources标记没有加载jar

我正在使用tomcat 9,并试图从PreResources标签下面加载所有与项目相关的jar。 External-lib文件夹位于tomcat目录中,符合’base’中提到的路径。 但是当部署应用程序时,我得到以下错误。 java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener 这是从web.xml调用的, org.springframework.web.context.ContextLoaderListener 在tomcat lib中,我们只有tomcat库,其余所有jar都在External-lib文件夹中。 由于我们有类似的webApp和jar太多,我们正在尝试外化它们而不是加载到webapp / web-inf / lib文件夹中。 请建议,使用PreResources元素从meta-inf / context.xml加载jar时我遗漏了什么。 这个PreResources元素的示例和文档非常少。 任何方向或帮助将不胜感激。