Spring

session/entitymanager is closed

蹲街弑〆低调 提交于 2021-02-18 12:17:01
问题 i have this hibernate dao and it works fine while testing in my local machine. but for some transaction it throws IllegalStateException. i believe it is because multiple users hitting at same time.(i may be wrong). UpdatePaymentDao @Repository public class UpdatePaymentImpl implements UpdatePayment { @Autowired SessionFactory sessionFactory; Session session; Transaction trans; private static final long LIMIT = 100000000000L; private static final long LIMIT2 = 10000000000L; private static long

RestTemplate set timeout per request

∥☆過路亽.° 提交于 2021-02-18 11:52:15
问题 I have a @Service with several methods, each method consumes a different web api. Each call should have a custom read timeout. Is it thread-safe to have one RestTemplate instance and change the timeout via the factory in each method like so ((HttpComponentsClientHttpRequestFactory)restTemplate.getRequestFactory()) .setReadTimeout(customMillis); My concern is that I'm changing the timeout on the factory and its not like a RequestConfig . Will this approach be thread-safe considering these

WebServiceContext injecting issue via @Resource annotation

送分小仙女□ 提交于 2021-02-18 11:45:09
问题 I am having issues with injecting WebServiceContext via @Resource annotation. I am using JAXWS + Spring combination. This is a piece of code I use. @WebService public class AdminWSImpl { @Resource private WebServiceContext context; ... } Part of my web.xml: ... <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <listener> <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class> </listener>

How does spring achieve dependency injection at runtime?

百般思念 提交于 2021-02-18 11:36:30
问题 Does anyone know what technique spring uses to achieve dependency injection at runtime? Does it simply use aspects (AOP) or is it something more complicated? 回答1: Spring does a lot of things, but dependency injection itself is actually a surprisingly simple mechanism. It starts with having a registry for classes that are available for injection. Classes that are added to this registry are examined using reflection. A DI framework will look for relevant annotations and constructors to

How does spring achieve dependency injection at runtime?

百般思念 提交于 2021-02-18 11:36:03
问题 Does anyone know what technique spring uses to achieve dependency injection at runtime? Does it simply use aspects (AOP) or is it something more complicated? 回答1: Spring does a lot of things, but dependency injection itself is actually a surprisingly simple mechanism. It starts with having a registry for classes that are available for injection. Classes that are added to this registry are examined using reflection. A DI framework will look for relevant annotations and constructors to

Spring Transaction not rolling back

我与影子孤独终老i 提交于 2021-02-18 11:20:10
问题 I have something like this: @Service @Transactional public class ServiceA { @Autowired SomeDAO1 dao1; @Autowired ServiceB serviceB; public void methodServiceA() { serviceB.someMethodThatRunsInsertIntoDB(); dao1.anotherMethodThatRunsInsertIntoDB(); } } @Service @Transactional public class ServiceB { @Autowired Dao2 dao2; public void someMethodThatRunsInsertIntoDB() { dao2.insertXXX(); } } My problem is: if serviceB.someMethodThatRunsInsertIntoDB() executes sucessfully but dao1

springboot整合zookeeper和dubbo

别来无恙 提交于 2021-02-18 09:49:17
序言 dubbo就是个rpc框架,之前都是一直在用,现在稍微总结下以备以后使用。 我就直接贴代码了,代码肯定能运行,如果运行不了那么看我之前的zookeeper配置,或者把我贴的代码重新复制下,实在不行请留言,我看到会回复的。 整体项目结构 项目是父子maven结构,父maven中基础jar包都依赖好了,子maven只需继承父maven,额外依赖自己的jar包就可以,其中 domain 是放实体类的, interfaceapi 是放提供者提供给消费者的接口的。 provider 是提供者 consumer 是消费者,不过真实项目中可能一个模块即是消费者又是提供者。所以自己需要的话直接写就行,用法都一样的。 2.主pom文件 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion>

springboot整合dubbo\zookeeper做注册中心

半城伤御伤魂 提交于 2021-02-18 08:59:44
  springboot整合dubbo发布服务,zookeeper做注册中心。前期的安装zookeeper以及启动zookeeper集群就不说了。   dubbo-admin-2.5.4.war:dubbo服务管理项目,下载完后部署到tomcat即可查看(登录的用户名和密码默认都是root)。 pom文件引入dubbo以及zkcli包: <!-- 引入dubbo-spring-boot-starter以及zkclient依赖 --> < dependency > < groupId > com.alibaba.spring.boot </ groupId > < artifactId > dubbo-spring-boot-starter </ artifactId > < version > 2.0.0 </ version > </ dependency > < dependency > < groupId > com.101tec </ groupId > < artifactId > zkclient </ artifactId > < version > 0.9 </ version > </ dependency > 1.dubbo服务端(提供dubbo服务) 目录结构如下: 配置文件如下 application.properties #################

spring profile 与maven profile

匆匆过客 提交于 2021-02-18 08:26:35
profile: n. 侧面,半面; 外形,轮廓; [航]翼型; 人物简介; vt. 描…的轮廓; 给…画侧面图; 为(某人)写传略; [机]铣出…的轮廓; 这个词具体是什么意思,参考: https://www.zhihu.com/question/28464897 我的理解,就是一个配置。 一、spring中的profile profile 说白了就是利用一个变量来控制加载哪些bean。主要用在实现在不同的环境下加载不同的bean。 比如在测试环境下,加载根据这个数据库的配信息生成的bean,在生产环境下使用另一个bean。 简单用法: 将spring-profile-test.xml和spring-profile-dev.xml都import入主配置文件中,但是由于spring.profile.active的值不同,真正加载的bean也不同(不满足profile值的bean不会被加载,此时相当于import了一个空文件) 在运行的使用配置下面参数来激活test环境需要加载的bean,profile的值可以有多个,测试需要用“,”隔开。 -Dspring.profiles.active=test 当然profile还有其他激活方法,如: DispatcherServlet的初始化参数传入 web app上下文参数传入 JNDI入口 环境变量 JVM系统属性