Spring @Service vs Object Service(Spring @Service vs Object Service)
我在春天有一个关于
@Service
的问题,但我没有找到任何关于它的回复。情况:
我有一个使用spring的
@RestController
的Web应用程序现在,对于我的服务层,我在一些项目中看到了两种处理方式
服务类上的
@Service
和控制器类上的@Autowired
(如果我们更改范围,创建一个单例的bean除外)创建一个像服务一样的对象
MyService服务=新的MySerivce()
所以我的问题是:
每次为控制器的每次调用创建一个对象都不会成为内存的问题? 如果我创建一个负载测试(使用Apache Jmeter)并发送1000个请求,它将创建1000个对象我的服务,所以可能是一个问题吗?
使用
@Service
创建单例不会成为内存的问题,但是,例如,spring将如何在1秒内处理1000个请求。 他会在某种队列上推送请求并一次执行一个吗?服务声明的最佳做法是什么?为什么?
如有任何回复,请提前感谢
I have a question about
@Service
in spring, but i didn't find any response about it.Situation :
I have a web application with
@RestController
using springNow for my service layer, I saw on some project two way of processing
@Service
on service class and@Autowired
on controller class (Create a bean that is a singleton excepted if we change the scope)Create a object like a service
MyService service = new MySerivce()
So my questions are :
Create a object each time for each call of controller will not be a issue for memory ? If i create a load test (with Apache Jmeter) and send 1000 requests, it will create 1000 object my service so could be a problem no ?
Create a singleton with
@Service
will not be a issue for memory but, how spring will handle 1000 requests on 1 seconds for example. Will he push requests on a sort of queue and execute one at a time ?What is the best practice for Service declaration and why ?
Thank in advance for any response
原文:https://stackoverflow.com/questions/50713088
最满意答案
你不必为此使用Raphaël,你可以使用vanilla JS(如果加载那个库也可以使用jQuery)。
el.mouseover(function () { document.getElementById('myHoverContents').style.display = 'block'; //show the div this.toFront(); this.attr({ cursor: 'pointer', fill: 'black', stroke: '#fff', 'stroke-width': '2', }); this.animate({ scale: '1.2' }, 200); }); el.mouseout(function () { document.getElementById('myHoverContents').style.display = 'none'; //hide the div this.animate({ scale: '1.05' }, 200); this.attr({ fill: '#003366' }); });
You don't have to use Raphaël for this, you can just use vanilla JS (or jQuery if you load that library too).
el.mouseover(function () { document.getElementById('myHoverContents').style.display = 'block'; //show the div this.toFront(); this.attr({ cursor: 'pointer', fill: 'black', stroke: '#fff', 'stroke-width': '2', }); this.animate({ scale: '1.2' }, 200); }); el.mouseout(function () { document.getElementById('myHoverContents').style.display = 'none'; //hide the div this.animate({ scale: '1.05' }, 200); this.attr({ fill: '#003366' }); });
相关问答
更多-
Kineticjs vs Raphaeljs(Kineticjs vs Raphaeljs)[2021-12-31]
RaphaelJS和KineticJS最大的区别在于RaphaelJS使用SVG,而KineticJS使用HTML5 Canvas进行可视化。 所以这取决于你在做什么样的项目。 这里有一些有用的链接,你应该检查有关SVG vs Canvas: 有关何时使用Canvas和SVG的想法 (也描述了混合方法) Simon Sarris在这个stackoverflow线程中出色的回复 (我还在同一个线程中发布了SVG和canvas之间的一些基准 ) 总结: 如果你想创建一些交互式图表,我会和RaphaelJS一起去 ... -
如何隐藏和显示div(How to hide and show div)[2023-06-09]
没有onmouseover功能,你可以使用mouseover或.on('mouseover',.....) 你可以这样做: $('#first').on('mouseover', function(){ $('#second').show(); $('#first').hide(); }); $('#second').on('mouseout', function(){ $('#first').show(); $('#second').hide(); }); 小提琴演示 ... -
您需要创建一个闭包和/或使用'this',因此创建的函数将知道它应用了哪个元素,而不仅仅是for循环中的最后一个元素。 有几种方法可以做到这一点,其中一种方法是创建其所指的城市的功能范围的直接功能。 或者你可以使用'this'来引用正确的元素。 for (var city in cities) { cities[city].hover(function () { this.attr({"fill": "#FF5B3A"}); }, function ...
-
在悬停时显示/隐藏特定Div,并在鼠标移出时隐藏div(Show/Hide Particular Div on hover and Hide a div on mouse out)[2023-10-29]
我为你做了一个工作小提琴: http : //jsfiddle.net/NKC2j/1780/ $(".sep-prod").each(function(){ $(".one,.two,.panel").hide(); $(this).hover(function(){ $(this).find(".middle-desc").hide(); $(this).find(".one").show(); },function ... -
你不必为此使用Raphaël,你可以使用vanilla JS(如果加载那个库也可以使用jQuery)。 el.mouseover(function () { document.getElementById('myHoverContents').style.display = 'block'; //show the div this.toFront(); this.attr({ cursor: 'pointer', fill: 'black', ...
-
ID应该是unique 。 所以我已将重复的ID更改为类。 此外,我们需要在此上下文中使用multiple selector以避免闪烁。 HTML:
RESPECT
需要在悬停时显示图像 - 使用raphaeljs的图像映射(need to display image upon hover - image map using raphaeljs)[2021-08-17]
我创建了一个模型buildingModel ,其中存储了所有需要的值,如image src和在悬停时创建的临时图像。 还有一个阵列可以容纳所有添加到纸张上的元素,方便使用。 随意试试吧。 window.onload = function () { var paper = new Raphael(document.getElementById('canvas_container'), 718, 454); var buildingModel = functio ...要读取的最简单的矢量图像格式是svg,因为svg是XML,XML只是纯文本。 使用Illustrator或Inkscape之类的东西将您的矢量图像转换为svg,然后在文本编辑器中打开它。 你会发现像和 这样的形状在Raphael中有着直接的等价关系。 例如, 对象在其d属性中定义了路径坐标,并且与Raphael中的路径具有相同的语法: 尝试这个。 你并不像其他人所说的那样需要JS,但我添加了一些额外的定位,所以剩下的元素不会在悬停时移动。 HTML: