文档库 最新最全的文档下载
当前位置:文档库 › Non-Eeuclidean spring embedders

Non-Eeuclidean spring embedders

Non-Eeuclidean spring embedders
Non-Eeuclidean spring embedders

Non-Euclidean Spring Embedders

Stephen G.Kobourov and Kevin Wampler

Abstract—We present a conceptually simple approach to generalizing force-directed methods for graph layout from Euclidean geometry to Riemannian geometries.Unlike previous work on non-Euclidean force-directed methods,ours is not limited to special classes of graphs,but can be applied to arbitrary graphs.The method relies on extending the Euclidean notions of distance,angle,and force-interactions to smooth non-Euclidean geometries via projections to and from appropriately chosen tangent spaces.In particular, we formally describe the calculations needed to extend such algorithms to hyperbolic and spherical geometries.We also study the theoretical and practical considerations that arise when working with non-Euclidean geometries.

Index Terms—Force-directed algorithms,spring embedders,non-Euclidean geometry,hyperbolic space,spherical space,graph drawing,information visualization.

?

1I NTRODUCTION

S OME of the most flexible algorithms for calculating layouts of simple undirected graphs belong to a class known as force-directed algorithms.Also known as spring embedders,such algorithms calculate the layout of a graph using only information contained within the structure of the graph itself,rather than relying on domain-specific knowl-edge.Graphs drawn with these algorithms tend to be aesthetically pleasing,exhibit symmetries,and tend to produce crossing-free layouts for planar graphs.

However,existing force-directed algorithms are re-stricted to calculating a graph layout in Euclidean geome-try,typically I R2,I R3,and,more recently,I R n for larger values of n.There are,however,cases where Euclidean geometry may not be the best option:Certain graphs may be known to have a structure which would be best realized in a different geometry,such as on the surface of a sphere or on a torus.In particular,3D mesh data can be parameter-ized on the sphere for texture mapping or graphs of genus one can be embedded on a torus without crossings. Furthermore,it has also been noted that certain non-Euclidean geometries,specifically hyperbolic geometry, have properties which are particularly well suited to the layout and visualization of large classes of graphs[16],[17].

We present a method by which a force-directed algorithm can be generalized so that it can compute a graph layout in any of a large class of geometries(known as Riemannian geometries),so long as the mathematics describing how the geometries behave are well described. Because of the particular usefulness of hyperbolic geometry and spherical geometry,with respect to graph drawing,information visualization,and graphics,we also present these mathematical properties for the case of H H2,two-dimensional hyperbolic space,and S S2,spherical space. Our method relies on extending the Euclidean notions of distances and angles to Riemannian geometries via projec-tions to and from appropriately chosen tangent spaces.The extended abstract[13]contains a summary of the results, whereas here we elaborate on the mathematical details and discuss some of the practical considerations of working with non-Euclidean geometries.

From a practical point of view,the hyperbolic and spherical cases are fairly straightforward and we have implemented spring embedder algorithms for both geo-metries.Thus,we are able to compare layouts obtained with the traditional Euclidean force-directed methods and those obtained with the generalized force-directed meth-ods in hyperbolic space and in spherical space,such as those in Fig.1.

2F ORCE-D IRECTED M ETHODS

Graph drawing has applications in many areas where relational data needs to be visualized,such as VLSI, software engineering,and databases;see the survey paper by Herman et al.[10].It is the subject of an annual symposium and several books on the subject are available [2],[12].While many algorithms have been developed for special classes of graphs,such as trees,tree-like graphs,and planar graphs,general graphs are most often visualized using force-directed methods.

Going back to1963,the graph drawing algorithm of Tutte[24]is one of the first force-directed graph drawing methods,based on barycentric representations.More traditionally,the spring layout method of Eades[3]and the algorithm of Fruchterman and Reingold[6]both rely on Hooke’s law for spring forces.In these methods,there are repulsive forces between all nodes,but also attractive forces between nodes which are adjacent.

Alternatively,forces between the nodes can be computed based on their graph theoretic distances,determined by the lengths of shortest paths between them.The algorithm of Kamada and Kawai[11]uses spring forces proportional to the graph theoretic distances.Other force-directed methods

.S.G.Kobourov is with the Department of Computer Science,University of

Arizona,Tucson,AZ85721.E-mail:kobourov@https://www.wendangku.net/doc/ff11061242.html,.

.K.Wampler is with the Department of Computer Science and Engineering,

University of Washington,CSE101,Allen Center,Box352350,Seattle,

WA98195-2350.E-mail:wampler@https://www.wendangku.net/doc/ff11061242.html,.

Manuscript received15Dec.2004;revised19Apr.2005;accepted3May

2005;published online8Sept.2005.

For information on obtaining reprints of this article,please send e-mail to:

tvcg@https://www.wendangku.net/doc/ff11061242.html,,and reference IEEECS Log Number TVCG-0256-1204.

1077-2626/05/$20.00?2005IEEE Published by the IEEE Computer Society

include that of Sugiyama and Misue[23],based on magnetic fields.

In general,force-directed methods define an objective function which maps each graph layout into a number in I Rtrepresenting the energy of the layout.This energy function is defined in such a way that low energies correspond to layouts in which adjacent nodes are near some prespecified distance from each other,but in which nonadjacent nodes are well-spaced.A layout for a graph is then calculated by finding a(often local)minimum of this objective function;see Fig.2.

One particularly useful way to find such a local minimum is through a gradient descent method.In this model,we calculate forces(often via the negative gradient of the energy function)which result from the interaction between the nodes in the graph.The nodes are then moved according to the net force acting upon them and the process is repeated until a steady state is reached or a maximum number of iterations is exceeded.

While early force-directed algorithms work well for small graphs,recently such algorithms have been extended to deal with graphs with hundreds of thousands of vertices. Harel and Koren[9]use a multiscale technique and Gajer et al.[7]combine this idea with intelligent placement of nodes to avoid local minima.Koren et al.[14]use techniques from spectral graph theory to quickly obtain layouts for even larger graphs.

With few exceptions,spring embedders thus far have been restricted to n-dimensional Euclidean space.This restriction is due in part to the simplicity of the algorithms when formulated in Euclidean space and in part to a reliance on the convenient structure of Euclidean space with well-defined notions of distances and angles.

Ostry[21]considers constraining force-directed algo-rithms to the surface of three-dimensional objects.This work is based on a differential equation formulation of the motion of the nodes in the graph and is flexible in that it allows a layout on almost any object,even multiple objects. Since the force calculations are made in Euclidean space, however,this method is inapplicable to certain geometries (e.g.,hyperbolic geometry).

https://www.wendangku.net/doc/ff11061242.html,youts of a title-word graph,obtained in H H2,S S2,and I R2.The graph has27nodes and50edges.

Another example of graph embedding within a non-Euclidean geometry is described in the context of generat-ing spherical parameterizations of 3D meshes.Gotsman et al.[8]describe a method for producing such an embedding using a generalization to spherical space of planar methods for expressing convex combinations of points.The implementation of the procedure is similar to the method described in this paper,but it may not lend itself to geometries other than spherical.

3H YPERBOLIC G RAPH D RAWING

Much of the work on non-Euclidean graph drawing has been done in hyperbolic space,which offers certain advantages over Euclidean space;see Munzner [17]and Munzer and Burchard [19].For example,in hyperbolic space,it is possible to compute a layout for a complete tree with both uniform edge lengths and uniform distribution of nodes.Further-more,some of the embeddings of hyperbolic space into Euclidean space naturally provide a fish-eye view of the space,which is useful for “focus+context”visualization,as shown by Lamping et al.[16].Previous algorithms for calculating the layouts of graphs in hyperbolic space,however,are either restricted by their nature to the layout of trees and tree-like graphs or to layouts on a lattice.

The hyperbolic tree layout algorithms function on the principle of hyperbolic sphere packing and operate by making each node of a tree,starting with the root,the center of a sphere in hyperbolic space.The children of this node are then given positions on the surface of this sphere and the process recurses on these children.By carefully computing the radii of these spheres,it is possible to create aesthetically pleasing layouts for the given tree.

Although some applications calculate the layout of a general graph using this method,the layout is calculated using a spanning tree of the graph and the extra edges are then added in without altering the layout [18].This method works well for tree-like and quasi-hierarchical graphs or for graphs where domain-specific knowledge provides a way to create a meaningful spanning tree.However,for general graphs (e.g.,bipartite or densely connected graphs)and without relying on domain specific knowledge,the tree-based approach may result in poor layouts.

Methods for generalizing Euclidean geometric algo-rithms to hyperbolic space,although not directly related to graph drawing,have also been studied.Recently,

van Wijk and Nuij [25]proposed a Poincare

′’s half-plane projection to define a model for 2D viewing and navigation.

Eppstein [4]shows that many algorithms which operate in Euclidean space can be extended to hyperbolic space by exploiting the properties of a Euclidean model of the space

(such as the Beltrami-Klein or Poincare

′).Our work follows a similar vein in that we use the Poincare

′model to implement the hyperbolic case of our technique,though it differs in that this mapping alone is not sufficient as the notions of

distance and linearity in the Poincare

′model do not match their Euclidean counterparts.

Hyperbolic and spherical space have also been used to display self-organizing maps in the context of data visualization.Ontrup and Ritter [20]and Ritter [22]extend the traditional use of a regular (Euclidean)grid,on which the self-organizing map is created,with a tessellation in spherical or hyperbolic space.An iterative process is then used to adjust which elements in the data set are represented by the intersections.Although the hyperbolic space method seems a promising way to display high-dimensional data sets,the restriction to a lattice is often undesirable for graph visualization.

4N ON -E UCLIDEAN S PRING E MBEDDING

Current implementations of force-directed algorithms per-form their calculations in I R n ,the standard Euclidean space.Euclidean geometry has properties which afford many conveniences for calculating a graph layout with a force-directed method.In particular,Euclidean space has a very convenient structure;it is easy to define distances and angles and the relationship between the vector representing the net force on an object and the appropriate motion of that object is quite straightforward.

A non-Euclidean geometry does not afford all of the conveniences above,so it is more difficult to define how the forces acting upon a graph should be calculated and how those forces should affect the layout of the graph.There is,however,a straightforward way to do this,provided we restrict ourselves to geometries which are smooth.Such geometries are known as Riemannian geometries.

We begin with a brief description of Riemannian geometry and manifolds.A manifold is a topological space that is locally Euclidean,that is,around every point,there is a neighborhood that is topologically the same as the open unit ball in I R n .We then show how the properties of manifolds can be used to extend force-directed calculations

KOBOUROV

AND WAMPLER:NON-EUCLIDEAN SPRING EMBEDDERS 759

Fig.2.An overview of a spring embedder in 2D Euclidean space.

to Riemannian geometries,such as spherical geometry,S S2, and hyperbolic geometry,H H2.

4.1Basics of Riemannian Geometry

In1894,Riemann described a generalization of the geometry of surfaces,which had been studied earlier by Gauss,Bolyai,and Lobachevsky.Two well-known special cases of Riemannian geometries are the two standard non-Euclidean types,spherical geometry and hyperbolic geo-metry.This generalization led to the modern concept of a Riemannian manifold.

Riemannian geometries have less convenient structure than Euclidean geometry,but they do retain many of the characteristics which are useful for force-directed graph layouts.A Riemannian manifold M has the property that, for every point x2M,the tangent space T x M is an inner product space.This means that,for every point on the manifold,it is possible to define local notions of length and angle.In effect,the tangent plane provides a bug’s-eye view of the manifold;see Fig.3.

Using the local notions of length,we can define the length of a continuous curve :?a;b !M by

lengthe T?

Z b

a

jj 0etTjj dt:

This leads to a natural generalization of the concept of a straight line to that of a geodesic,where the geodesic between two points u;v2M is defined as a continuously differentiable curve of minimal length between them.These geodesics in Euclidean geometry are straight lines and,in spherical geometry,they are arcs of great circles;see Fig.4. We can similarly define the distance between two points, dex;yT,as the length of a geodesic between them.

4.2Application to Spring Embedders

As mentioned above,one of the convenient properties of Riemannian manifolds is that,at every point,there exists a well-structured tangent space.We utilize these tangent spaces to generalize spring embedders to arbitrary Rie-mannian geometries.

In Euclidean space,the relationship between a pair of nodes is defined along lines:The distance between the two nodes is the length of the line segment between them and forces between the two nodes act along the line through them.These notions of distance and forces can be extended to a Riemannian geometry by having these same relation-ships be defined in terms of the geodesics of the geometry, rather than in terms of Euclidean lines.

The tangent space is also useful in dealing with the interaction between one point and several other points in non-Euclidean geometries.Consider three points x,y,and z in a Riemannian manifold M where there is an attractive force from x to y and z.As can be easily seen in the Euclidean case(but also true in general),the net force on x is not necessarily in the direction of y or z and,thus,the natural motion of x is along neither the geodesic toward y nor that toward z;see Fig.5.Determining the direction in which x should move requires the notion of angle.

Since the tangent space at x,being an inner product

space,has enough structure to define lengths and angles, we do the computations for calculating the forces on x in T x M.In order to do this,we define two functions for every point x2M as follows:

x:M!T x M

à1

x

:T x M!M:

These two functions map points in M to and from the tangent space of M at x,respectively.We require that x and

à1

x

satisfy the following constraints:

1. à1

x

e xeyTT?y for all y2M.

2.jj xeyTjj?dex;yT.

3. x preserves angles about the origin.

Using these functions,it is now easy to define the way in which the nodes of a given graph G?eV;ETinteract with each other through forces.In the general framework for this algorithm,we consider each node individually and calculate its new position based on the relative locations of the other nodes in the graph(repulsive forces)and on its adjacent edges (attractive forces).Pseudocode for a traditional Euclidean

760IEEE TRANSACTIONS ON VISUALIZATION AND COMPUTER GRAPHICS,VOL.11,NO.6,NOVEMBER/DECEMBER

2005

Fig.3.The tangent plane:a bug’s eye view of a Riemannian

manifold.

Fig.4.A curve and its derivative in the tangent space.

spring embedder and its non-Euclidean counterpart are in Fig.6.

Given a node v i 2V eG Twith position x ,we use x to map the positions of the relevant nodes of G into T x M (nodes that are used in computing x ’s new location).A standard force equation can then be used to calculate the force,f ,upon v i as a vector in T x M .Given the vector in T x M ,the new position,x 0of v i in T x M is calculated using standard techniques,typically by multiplying f by a scalar.The

desired position of v i in M is then given by à1

x

ex T.An overview of the process is in Fig.7.

5H YPERBOLIC G EOMETRY

5.1Motivation

One of the most useful applications for our non-Euclidean force-directed method is that it allows the layout of a general graph to be calculated in hyperbolic space (space of constant negative curvature).This provides a functionality beyond current hyperbolic graph layout techniques.Such functionality is desirable because of both the geometric properties of hyperbolic space and of the properties of some of the more common ways of mapping hyperbolic geometry into Euclidean space.

The study of hyperbolic geometry began in the 18th century [1].Hyperbolic geometry is particularly well suited to graph layout because it has “more space”than Euclidean geometry—in the same sense that spherical geometry has “less space.”To illustrate this,consider the relationship between the radius and circumference of a circle in a two-dimensional geometry.In Euclidean geometry,the relationship is linear with a factor of 2 .In spherical geometry,however,the circumference is bounded above by a constant (the circumference of a great circle on the sphere).With hyperbolic geometry,the opposite is the case:The circumference of a circle increases exponentially with its radius.

The applicability of this geometric property to graph layout is well illustrated with the example of a tree.The number of nodes at a certain depth in the tree typically increases exponentially with the depth.Thus,layouts in Euclidean space result in characteristic long edges near the root and short edges near the leaves.In hyperbolic space,however,it is possible to lay out the tree with a uniform distribution of the nodes and with uniform edge lengths.

5.2Hyperbolic Projections

In order to display a layout in hyperbolic geometry,it is necessary to map the figure into the (two-dimensional)Euclidean geometry of a computer monitor.There are numerous ways of doing this,two of the most common being

the Poincare

′disk and Beltrami-Klein projections.In both of these cases,the hyperbolic space is mapped onto the open unit disk f z 2I R 2:j z j <1g .To obtain such projections,it is necessary to distort the space,which,in these cases,takes the form of compressing the space near the boundary of the unit disk,giving the impression of a fish-eye view.This naturally provides a useful focus+context technique for visualizing the layouts of the graph;see Fig.10.

In the Beltrami-Klein projection,straight lines are mapped to straight lines,but angles are not necessarily preserved.Thus,each line in hyperbolic space is mapped to a chord of the unit disk and two lines are nonintersecting if their associated chords are nonintersecting.Furthermore,the distance between two points,ex;y Tand eu;v T,in the Beltrami-Klein model is not given by their Euclidean distance,but,rather,by

arccos 1àxu àyv

??????????????????????????????????????????????????????e1àx 2ày 2Te1àu 2àv 2Tp "#

:

The Poincare

′disk model preserves angles,but distorts lines.A line in hyperbolic space is mapped to a circular arc which intersects the unit circle at right angles (chords passing through the origin are considered to be such arcs).As with the Beltrami-Klein model,distances in the projec-tion are not equal to the the hyperbolic distances between

the points.The Poincare

′disk model also compresses the space slightly less at the edges,which,in some cases,can have the advantage of allowing a better view of the context around the center of projection.In this paper,we focus on

an implementation which uses the Poincare

′disk model.5.3Tangent Space Mapping

There are many possible ways to compute the mapping to and from the tangent space.Here,we present the details

KOBOUROV

AND WAMPLER:NON-EUCLIDEAN SPRING EMBEDDERS 761

https://www.wendangku.net/doc/ff11061242.html,puting the net force on a node x as a result of its interaction with two

other nodes,y and z .

Fig.6.A generic Euclidean spring embedder and its non-Euclidean counterpart.

about one such mapping,which we also implemented.As illustrated in Fig.6,the problem reduces to defining the mappings x and à1x so that they meet the three criteria from Section4.1.

Internally,each node in the graph is assigned a position z?ex;yTwithin the unit disk,representing the Poincare′coordinates of that https://www.wendangku.net/doc/ff11061242.html,ing the Poincare′coordinates for the positions of points allows us to take advantage of the property that,in a Poincare′projection,angles are preserved and circles and lines are mapped to circles and lines.Since hyperbolic space is uniform,we can“recenter”the projection about any point,z0,by applying a conformal (angle preserving)mapping which maps z0to the origin,the boundary of the unit circle to itself,and which maps circles and lines to circles and lines.By treating the position of the node as a complex number,we can define such a mapping as the linear fractional transformation:

f z

0ezT?

zàz0

1àz0z

:

It is also easy to compute the inverse of this function:

fà1 z0ezT?

àzàz0

àz0zà1

:

By using f to recenter the projection about z0,we force all geodesics passing through z0to be projected as line segments passing through the origin.Furthermore,the Euclidean angle formed between two such lines is equal to the angle by which the two corresponding geodesics intersect.This satisfies criteria1and3for the function z,but the norm of the points (their distances from the origin)after the mapping f is not equal to their distances from z0in the hyperbolic space(as a consequence,the range of the inverse function is also only the unit disk).To remedy this,we rescale the points such that their distances from the origin are indeed equal to their hyperbolic distance from z0.Note that this does not alter angles at the origin.This is accomplished with another mapping,denoted by g,as follows:

g z

ezT?

z

log

1tjj z jj

:

It is also possible to find the inverse of this mapping:

gà1

z0

ezT?

z

jj z jj

1àe jj z jj

1te jj z jj

:

Now,we can define z

by composing these two mappings:

z

?g f:

Similarly,we can define à1z

as:

à1

z0

?fà1 gà1:

It can be verified that z

and à1z

,as defined above, indeed satisfy the three criteria for functions mapping to and from the tangent space and,thus,these two functions are sufficient to implement a spring embedder in hyperbolic geometry.

6S PHERICAL G EOMETRY

As a further example for generalizing spring embedders to non-Euclidean geometry,we also consider spherical geo-metry.As with hyperbolic geometry,spherical geometry has a constant curvature and the equations for mapping to and from the tangent space can be calculated analytically.

Each point x in a spherical geometry is defined by its coordinates, 2?0;2 Tand 2?0; T,representing the longitude and latitude of the point,respectively.This spherical geometry can then be embedded as a sphere in three-dimensional Euclidean space by the parameterization

762IEEE TRANSACTIONS ON VISUALIZATION AND COMPUTER GRAPHICS,VOL.11,NO.6,NOVEMBER/DECEMBER

2005 Fig.7.An overview of a non-Euclidean spring embedder.

emb ex T?ecos sin ;cos ;sin sin T.We can calculate the tangent plane at any point on the sphere by taking the space spanned by the two partial derivative vectors:

u x ?eàsin sin ;0;cos sin T;v x ?ecos cos ;àsin ;sin cos T:

Note that,if applied at either of the poles,these equations fail to yield a valid space,so,in these cases,the u and v vectors can be hard-coded to,for example,e1;0;0Tand e0;0;1T.

We can now compute x ey Tfor any points x and y in the spherical geometry by projecting the embedding of y ,emb ey Tonto the tangent plane at x with eemb ey Táu x ;emb ey Táv x T.To complete the mapping,we have only to set the length of this vector equal to the length of the geodesic between x and y :

r áarccos sin x sin y cos y à x tcos x cos y ??

;where r is the radius of curvature of the geometry.An illustration of this mapping can be seen in Fig.8.

The inverse of this mapping à1

x ey T,illustrated in Fig.9,can also be computed in a similar geometric manner.First,we compute a vector,p ,perpendicular to that from x ey Tin the tangent space (for example,by p x ? x ey Ty ,p y ?à x ey Tx ).The vector p is then mapped to the corresponding vector in three-dimensional space by up x tvp y .This vector is

perpendicular to the plane containing the origin, à1

x ex T

and à1x ey T.Thus,the desired point à1

x ey Tcan be obtained

by rotating à1

x ex Tabout this axis so that the arc length

traveled by à1x ex Tis equal to the norm of à1

x ey T.In radians,

this angle is j y j

r .Since this rotated vector is in Euclidean space,the calculation can be completed by projecting it back

onto the sphere by calculating ?arctan z

x , ?arccos y .

7P RACTICAL C ONSIDERATIONS

We have implemented both the hyperbolic and the spherical layouts as a part of the graphael system [5].In addition to specifying the tangent space mappings which define how the nodes of a graph respond to the forces of other nodes,there are further practical considerations to be addressed,particularly in the layout of larger graphs.Some of these considerations are specific to the space in which the graph is to be embedded,as,for example,hyperbolic space

is susceptible to different layout problems than spherical.

We present some of the images we obtained as well as describe some of the practical challenges posed by the non-Euclidean geometries.

7.1Example Layouts in H H 2and S S 2

Fig.1shows a title-word graph obtained from the graph drawing literature.This graph has 27nodes and 50edges.The graph nodes correspond to title-words from papers in the Proceedings of the 1999Symposium on Graph Drawing [15].The size of a node is determined by the frequency of the corresponding word and an edge is placed between two nodes if they cooccur in at least one paper.

The images in Fig.1show layouts of the same graph

obtained in H H 2,S

S 2,and I R 2,obtained using our implementa-tion of the algorithms described in this paper.Fig.10shows four views of the graph using different centers of attention and nicely illustrates the focus+context properties of hyper-bolic space.Fig.11shows four views of the same graph in spherical space,again using different centers of attention.7.2Curvature Considerations

We have found that,for spaces of high curvature (both spherical and hyperbolic),there is a tendency to reach a local minimum that does not correspond to a visually pleasing layout.In spherical space,this typically occurs when the space is too small to accommodate an optimal layout of the graph.In such situations,the repulsive forces between nodes dominate and the layout “locks”into an unsatisfactory state.

In hyperbolic space,it is possible for a similar problem to occur.In this case,rather than due to lack of enough space to achieve a satisfactory layout,an overabundance of space allows the nodes to space themselves out too easily.For some intuitive explanation,consider that,since the circum-ference of a circle grows exponentially with its radius,in a space of high enough curvature (or,equivalently,large enough edge length),it is possible to lay out any fixed number of nodes near the boundary of the circle so that the distance between neighboring nodes on the circle is equal to the diameter of the circle.Thus,adjacent nodes are as likely to be neighboring on the circle as they are to be at opposite ends.This often results in a layout with many undesirable edge crossings.

KOBOUROV

AND WAMPLER:NON-EUCLIDEAN SPRING EMBEDDERS 763

Fig.8.Mapping to the tangent space via mapping to the tangent plane,followed by a renormalization for the length

of the vector in the tangent space.

Fig.9.Mapping from the tangent space via a rotation.The dotted line represents the axis of rotation,up x tvp y .

We have considered ways to address the curvature problem.It is likely that multiscale layout methods along the lines of [7]and [9]will be of some help in reducing these effects.It is also likely that force equations designed specifically to work well within a particular geometry could avoid such unsatisfactory layouts.Finally,we have also found that better layouts can be achieved by beginning the iterative layout process in a space which is nearly Euclidean,then gradually increasing the magnitude of the curvature of the space during the layout process until it reaches the desired value.

It is worth noting that some graphs are better suited to non-Euclidean spaces than other.A regular grid,for example,is well suited to Euclidean space.In a hyperbolic space of high curvature,however,the layout of the grid is quite distorted.This can be thought of as the inverse case of

the distortion that is necessary to embed a tree in Euclidean space.How well hyperbolic space suits a given graph can be observed by looking at a plot of the sum of all the magnitudes of the forces acting in a graph versus the curvature of the space the graph is embedded in;see Fig.12.In graphs that can be embedded well in hyperbolic space,such as trees,after a certain curvature,we see monotoni-cally decreasing stress.In graphs better suited to Euclidean space,such as grids,we instead see an early decrease followed by monotonically increasing stress.

7.3Multiscale Considerations

Multiscale layout methods are needed even in the Euclidean case,in order to apply spring embedder algo-rithms.These methods typically greatly improve the speed and quality with which large graphs can be laid out.In

764IEEE TRANSACTIONS ON VISUALIZATION AND COMPUTER GRAPHICS,VOL.11,NO.6,NOVEMBER/DECEMBER

2005

https://www.wendangku.net/doc/ff11061242.html,youts of the title-word graph with different centers of attention in hyperbolic space.

addition,multiscale layouts may be useful in avoiding highly suboptimal layouts.Unfortunately,such methods often employ techniques which cannot be directly applied using the framework for non-Euclidean graph layouts that we have set up.Consider,for example,estimating the position of a new node by interpolating the positions of already laid-out nodes[7].For three or more nodes,this interpolation cannot be directly expressed in a general Riemannian geometry using the tools we have described.

Although it is possible to analytically calculate such interpolations for certain geometries,it is not always necessary to do so.Since such techniques often function as rough heuristics,in many cases,it is possible to perform the calculations in the tangent space of one of the nodes involved.For example,to interpolate the positions of some set of nodes,one node could be selected at random,and the calculations done within the tangent space of this node. 7.4Oscillations in S S2

Many spring embedders use a heuristic intended to expedite the graph’s convergence to a steady layout—nodes which are changing their direction are slowed down while nodes moving in a straight line are sped up.This dampens oscillations in the layout process and normally improves layout quality.In spherical space,however,it is possible for a node to oscillate and move in a straight line,as occurs when a node repeatedly travels around the entire space.In such cases,these heuristics can actually degrade the layout by reinforcing this sort of motion.While such heuristics seem to pose no fundamental problems,they should be used with care.

KOBOUROV AND

WAMPLER:NON-EUCLIDEAN SPRING EMBEDDERS765 https://www.wendangku.net/doc/ff11061242.html,youts of the title-word graph with different centers of attention in spherical space.

7.5Precision in H H2

Hyperbolic space also has its own set of problems which must be surmounted in calculating the layout of certain graphs.This problem arises from one of the most useful features of hyperbolic space—that the circumference of a circle grows exponentially with its radius.This means that, to achieve a given spatial resolution,floating-point repre-sentations of positions in hyperbolic space must use a number of bits proportional to the distance between nodes in the layout.If points are not represented in this manner, the layout of a large graph can be subject to serious floating-point errors.While the precision problem can be addressed with the traditional arbitrary precision floating-point representation,this would impose a speed penalty,prohi-bitively large for large graphs.

Note,however,that the further away two nodes are,the less accurately we need to calculate their absolute positions in tangent space.This makes it desirable to use a point representation better suited to calculating the relative position of nodes than their absolute positions.One such representation would be a discrete lattice over the hyper-bolic plane,such as a hyperbolic tessellation.The position of each node can then be stored as a combination of a designation for the nearest lattice point and an offset from that point.This offset can be stored as a point in the Poincare′disk,with the origin being the nearest lattice point. The relative positions of two points can then be compared by taking the offset into account and walking the lattice from one to the other.

8C ONCLUSION AND F UTURE W ORK

We presented a simple algorithm for generalizing a spring embedder to an arbitrary Riemannian geometry.This method relies on only very general features of spring embedders and,thus,can be applied in principle to most force-directed layout methods.We also presented the details for the specific cases of hyperbolic and spherical geometries as well as some layouts obtained with our implementation.

Although the methods presented here are sufficient to generalize a spring embedder into any Riemannian geome-try,there are still many practical concerns that need to addressed.While the mathematics needed to determine x and à1x are relatively simple for the cases of hyperbolic and spherical geometries,this is not always the case.It is not even possible,in general,to analytically calculate the geodesic between two points in an arbitrary geometry.It is likely the case that,for more complex geometries,approximate methods will have to be used to determine x and à1x.

Perhaps most importantly with regard to information visualization,we would like to make our method scalable.As with traditional force-directed algorithms,our method does not work well for very large graphs.Finding low energy states becomes increasingly difficult as the input graphs get larger. Multiscale methods and high dimensional embedding have been successfully used to extend Euclidean spring embed-ders.Generalizing the non-Euclidean spring embedders along the lines of[7]and[9]should be possible.This would allow us to experiment with the layouts of very large graphs in these geometries and,thus,to fully exploit their properties to better visualize large data sets.

A CKNOWLEDGMENTS

The authors would like to thank the anonymous referees of the journal and conference versions of the paper for their comments and suggestions.This work is partially sup-ported by the US National Science Foundation under grant ACR-0222920.

R EFERENCES

[1]J.W.Anderson,Hyperbolic Geometry.Springer-Verlag,1999.

[2]G.Di Battista,P.Eades,R.Tamassia,and I.G.Tollis,Graph

Drawing:Algorithms for the Visualization of Graphs.Englewood Cliffs,N.J.:Prentice Hall,1999.

[3]P.Eades,“A Heuristic for Graph Drawing,”Congressus Numer-

antium,vol.42,pp.149-160,1984.

[4] D.Eppstein,“Hyperbolic Geometry,Mo¨bius Transformations,

and Geometric Optimization,”Proc.MSRI Introductory Workshop Discrete and Computational Geometry,2003.

[5] C.Erten,P.J.Harding,S.G.Kobourov,K.Wampler,and G.Yee,

“GraphAEL:Graph Animations with Evolving Layouts,”Proc.

11th Symp.Graph Drawing,pp.98-110,2003.

[6]T.M.J.Fruchterman and E.M.Reingold,“Graph Drawing by

Force-Directed Placement,”Software—Practice and Experience, vol.21,no.11,pp.1129-1164,1991.

[7]P.Gajer,M.T.Goodrich,and S.G.Kobourov,“A Multi-Dimen-

sional Approach to Force-Directed Layouts of Large Graphs,”

Computational Geometry:Theory and Applications,vol.29,no.1, pp.3-18,2004.

[8] C.Gotsman,X.Gu,and A.Sheffer,“Fundamentals of Spherical

Parameterization for3D Meshes,”ACM Trans.Graphics,vol.22, pp.358-363,2003.

[9] D.Harel and Y.Koren,“A Fast Multi-Scale Method for Drawing

Large Graphs,”J.Graph Algorithms and Applications,vol.6,pp.179-202,2002.

[10]I.Herman,G.Melanc?on,and M.S.Marshall,“Graph Visualization

and Navigation in Information Visualization:A Survey,”IEEE Trans.Visualization and Computer Graphics,vol.6,no.1,pp.24-43, Jan.-Mar.2000.

[11]T.Kamada and S.Kawai,“An Algorithm for Drawing General

Undirected Graphs,”Information Processing Letters,vol.31,no.1, pp.7-15,Apr.1989.

[12]M.Kaufmann and D.Wagner,Drawing Graphs:Methods and

Models.Springer-Verlag,2001.

766IEEE TRANSACTIONS ON VISUALIZATION AND COMPUTER GRAPHICS,VOL.11,NO.6,NOVEMBER/DECEMBER

2005

Fig.12.Plot of the stress in the final layout of a graph as a function of the (negative of the)curvature of the space it is embedded in.This is only intended to compare the relative shapes of the stress curves and the y-axis has been normalized for each graph so that its values range from zero to one.

[13]S.G.Kobourov and K.Wampler,“Non-Euclidean Spring Embed-ders,”Proc.10th Ann.IEEE https://www.wendangku.net/doc/ff11061242.html,rmation Visualization (InfoVis),pp.207-214,2004.

[14]Y.Koren,L.Carmel,and D.Harel,“ACE:A Fast Multiscale

Eigenvector Computation for Drawing Huge Graphs,”Proc.IEEE https://www.wendangku.net/doc/ff11061242.html,rmation Visualization,pp.123-144,2002.

[15]Proc.Seventh Int’l Symp.Graph Drawing,J.Kratochvil,ed.,1999.[16]https://www.wendangku.net/doc/ff11061242.html,mping,R.Rao,and P.Pirolli,“A focus+context Technique

Based on Hyperbolic Geometry for Visualizing Large Hierar-chies,”https://www.wendangku.net/doc/ff11061242.html,puter Human Interaction,pp.401-408,1995.

[17]T.Munzner,“H3:Laying Out Large Directed Graphs in 3D

Hyperbolic Space,”Proc.IEEE https://www.wendangku.net/doc/ff11061242.html,rmation Visualization,https://www.wendangku.net/doc/ff11061242.html,vagno and W.Reisig,eds.,pp.2-10,1997.

[18]T.Munzner,“Drawing Large Graphs with h3viewer and Site

Manager,”Proc.Sixth Symp.Graph Drawing,pp.384-393,1998.[19]T.Munzner and P.Burchard,“Visualizing the Structure of the

World Wide Web in 3D Hyperbolic Space,”Proc.Symp.Virtual Reality Modeling Language,pp.33-38,1996.

[20]J.Ontrup and H.Ritter,“Hyperbolic Self-Organizing Maps for

Semantic Navigation,”Proc.Advances in Neural Information Processing Systems 14,pp.1417-1424,2001.

[21] D.I.Ostry,“Some Three-Dimensional Graph Drawing Algo-rithms,”master’s thesis,Univ.of Newcastle,Australia,1996.

[22]H.Ritter,“Self-Organizing Maps on Non-Euclidean Spaces,”

Kohonen Maps,S.Oja and E.Kaski,eds.,pp.97-110,1999.

[23]K.Sugiyama and K.Misue,“Graph Drawing by the Magnetic

Spring Model,”J.Visual Languages and Computing,vol.6,no.3,pp.217-231,1995.

[24]W.T.Tutte,“How to Draw a Graph,”Proc.London Math.Soc.,

vol.13,no.52,pp.743-768,1963.

[25]J.J.van Wijk and W.A.A.Nuij,“A Model for Smooth Viewing and

Navigation of Large 2D Information Spaces,”IEEE Trans.Visualization and Computer Graphics,vol.10,no.4,pp.447-458,July/Aug.2004.

Stephen G.Kobourov received BS degrees in computer science and mathematics from Dart-mouth College (1995),the MS degree in computer science from Johns Hopkins Univer-sity (1997),and the PhD degree in computer science from Johns Hopkins University (2000).He is currently an assistant professor in the Computer Science Department at the University of Arizona.His primary research interests are in geometric algorithms,graph drawing,and in-formation visualization.He was program cochair of the International Symposium on Graph Drawing in 2002and was a coorganizer of a Dagstuhl seminar on Graph Drawing in 2005.

Kevin Wampler received BS degrees in mathe-matics and computer science from the University of Arizona (2003)and is currently pursuing the PhD degree in computer science at the Uni-versity of Washington.His primary research interests are in computer graphics,computer vision,artificial intelligence,and information visualization.

.For more information on this or any other computing topic,please visit our Digital Library at https://www.wendangku.net/doc/ff11061242.html,/publications/dlib.

KOBOUROV AND

WAMPLER:NON-EUCLIDEAN SPRING EMBEDDERS 767

SpringMVC配置的基本步骤

Springmvc框架配置步骤 小弟是个新手,有不对的地方请tell me,一起研究探讨。谢谢。 1062140832@https://www.wendangku.net/doc/ff11061242.html, 配置springmvc框架其实不是很难,要现有一个总体的认识,确定要分几步,每一步主要是干什么,不要太盲目。 以为web.xml是项目的入口,所以所有的配置文件,都必须引入到wem.xml中,不然,配置了等于没用。所以,要先从入口入手。 配置web.xml 1、首先引入springmvc-servlet.xml文件 springMVC org.springframework.web.servlet.DispatcherServlet contextConfigLocation /WEB-INF/spring/mvc/springmvc-servlet.xml 1 2、将spring加载到web.xml中 org.springframework.web.context.ContextLoaderListener 3、配置上下文路径 contextConfigLocation /WEB-INF/spring/spring.xml,/WEB-INF/spring/spring-*.xml 说明:如果有很多的关于spring的配置文件,建议分开写,比如事务一个文件(spring-transaction.xml),springmvc-hibernate.xml一个配置文件,这样方便读写。

spring配置文件各个属性详解

spring配置文件各个属性详解 分类:spring 2012-08-09 11:25 9316人阅读评论(2) 收藏举报springaophibernateattributesxhtmlwebsphere 目录(?)[+]一、引用外部属性文件 classpath:mail.properties classpath:jdbc.properties 我们定义了一个PropertyPlaceholderConfigurer类的实例,并将其位置属性设置为我们的属性文件。该类被实现为Bean工厂的后处理器,并将使用定义在文件中的属性来代替所有的占位符(${...}value)。 注意: 而在spring2.5的版本中提供了一种更简便的方式,如: 1. 这样以后要使用属性文件中的资源时,可以使用${属性名}来获得。 二、常用数据源的配置 第一种是:DBCP数据源,(需要加入2个jar文件,在spring中的lib下 jakarta-commons/commons-dbcp.jar和commons-pools.jar)主要配置如下:

spring6种配置datasource的方法

在Spring3中,配置DataSource的方法有6种。 JDBCSpringXMLMicrosoftHTML 在Spring3中,配置DataSource的方法有五种。 第一种:beans.xml Xml代码 1. 3. 4. 6. 7. 8. 第二种:beans.xml 2. 3. 4. 6. 7. 8. 9. 10. 在src文件夹里新建一个jdbc.properties文件,里面的内容为如下: Xml代码 1.jdbc.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriv er

Spring简介

spring 年编著的《Expert one to one J2EE design and development

Spring Logo 书中,对Java EE正统框架臃肿、低效、脱离现实的种种现状提出了质疑,并积极寻求探索革新之道。以此书为指导思想,他编写了interface21框架,这是一个力图冲破Java EE传统开发的困境,从实际需求出发,着眼于轻便、灵巧,易于开发、测试和部署的轻量级开发框架。Spring框架即以interface21框架为基础,经过重新设计,并不断丰富其内涵,于2004年3月24日,发布了1.0正式版。同年他又推出了一部堪称经典的力作《Expert one-to-one J2EE Development without EJB》,该书在Java世界掀起了轩然大波,不断改变着Java开发者程序设计和开发的思考方式。在该书中,作者根据自己多年丰富的实践经验,对EJB的各种笨重臃肿的结构进行了逐一的分析和否定,并分别以简洁实用的方式替换之。至此一战功成,Rod Johnson成为一个改变Java世界的大师级人物。 传统J2EE应用的开发效率低,应用服务器厂商对各种技术的支持并没有真正统一,导致J2EE的应用没有真正实现Write Once及Run Anywhere的承诺。Spring作为开源的中间件,独立于各种应用服务器,甚至无须应用服务器的支持,也能提供应用服务器的功能,如声明式事务等。 Spring致力于J2EE应用的各层的解决方案,而不是仅仅专注于某一层的方案。可以说Spring是企业应用开发的“一站式”选择,并贯穿表现层、业务层及持久层。然而,Spring并不想取代那些已有的框架,而是与它们无缝地整合。 编辑本段简介 Spring是一个开源框架,它由Rod Johnson创建。它是为了解决企业应用开发的复杂性而创建的。Spring使用基本的JavaBean来完成以前只可能由EJB完成的事情。然而,Spring的用途不仅限于服务器端的开发。从简单性、可测试性和松耦合的角度而言,任何Java应用都可以从Spring中受益。 ◆目的:解决企业应用开发的复杂性 ◆功能:使用基本的JavaBean代替EJB,并提供了更多的企业应用功能 ◆范围:任何Java应用 简单来说,Spring是一个轻量级的控制反转(IoC)和面向切面(AOP)的容器框架。 ◆轻量——从大小与开销两方面而言Spring都是轻量的。完整的Spring框架可以在一个大小只有1MB 多的JAR文件里发布。并且Spring所需的处理开销也是微不足道的。此外,Spring是非侵入式的:典型地,Spring应用中的对象不依赖于Spring的特定类。 ◆控制反转——Spring通过一种称作控制反转(IoC)的技术促进了松耦合。当应用了IoC,一个对象依赖的其它对象会通过被动的方式传递进来,而不是这个对象自己创建或者查找依赖对象。你可以认为IoC 与JNDI相反——不是对象从容器中查找依赖,而是容器在对象初始化时不等对象请求就主动将依赖传递给它。 ◆面向切面——Spring提供了面向切面编程的丰富支持,允许通过分离应用的业务逻辑与系统级服务(例如审计(auditing)和事务(transaction)管理)进行内聚性的开发。应用对象只实现它们应该做的——完成业务逻辑——仅此而已。它们并不负责(甚至是意识)其它的系统级关注点,例如日志或事务支持。 ◆容器——Spring包含并管理应用对象的配置和生命周期,在这个意义上它是一种容器,你可以配置你的每个bean如何被创建——基于一个可配置原型(prototype),你的bean可以创建一个单独的实例或者每次需要时都生成一个新的实例——以及它们是如何相互关联的。然而,Spring不应该被混同于传统的重量级的EJB容器,它们经常是庞大与笨重的,难以使用。

Spring考试

1. (单选题)下列关于Spring配置文件的说法不正确的是 o A. Spring默认是读取/WEB-INF/配置文件 o B. Spring的配置文件可以配置在类路径下,并可以重命名,但是需要在文件中指定 o C. 把文件放到src目录下,Spring也可以读到 o D. 可以通过在中的进行指定 Spring配置文件 正确答案:C 把文件放到src目录下,需要在web。xml里设置 contextConfigLocation /WEB-INF/classes/ 可以让spring读到 2. (单选题)下列关于Spring特性中IoC描述错误的是 o A. IoC就是指程序之间的关系由程序代码直接操控 o B. 所谓“控制反转”是指控制权由应用代码转到外部容器,即控制权的转移 o C. IoC将控制创建的职责搬进了框架中,从应用代码脱离开来 o D. 使用Spring的IoC容器时只需指出组件需要的对象,在运行时Spring的IoC 容器会根据XML配置数据提供给它

正确答案:A IOC是来完成相互依赖的对象的创建、协调工作。 3. (单选题)下列关于Spring的装配模式(default-autowire)描述不正确的是 o A. Spring中,至少有两种装配模式,按“类型”和“名字” o B. Spring中默认是按名字进行装配的 o C. 可以用default-autowire=”byType”配置按类型装配 o D. 一旦在一个Spring配置文件中配置了default-autowire=”byType”,其它的配置文件也是按此种装配方式进行装配 正确答案:D 在标签中指定default-autowire属性,那么对于子标签 如果没有单独的设置autowire属性,那么将采用父标签 的default-autowire属性的模式,如果单独设置了autowire 属性,则采用自己的模式 4. (单选题)下列选项关于Spring的核心机制——依赖注入的描述正确的是 o A. 所谓依赖注入就是明确地定义组件接口,独立开发各个组件,然后根据组件间的依赖关系组装运行的设计开发模式 o B. Spring不负责管理bean之间的关系 o C. 节点有可选的子节点,用于注入bean的属性 o D. 在Spring的配置文件中,使用来创建Bean的实例 正确答案:B Spring通过一个配置文件描述Bean及Bean之间的依赖关系,利用java语言的反射功能实例化Bean并建立Bean之间的依赖关系。spring的ioc容器在完成这些底层工作的基础上,还提供了bean实例缓存,生命周期管理,bean实例代理,事件发布,资源装载等高级服务 5.

spring在web.xml中的配置

把如下代码添加到web.xml即可完成spring的基本配置 SetCharacterEncoding org.springframework.web.filter.CharacterEncodingFilter encoding UTF-8 forceEncoding true SetCharacterEncoding /* contextConfigLocation /WEB-INF/applicationContext.xml, /WEB-INF/action-servlet.xml org.springframework.web.context.ContextLoaderListener

spring配置

作者简介: Craig Walls是Texas-based公司的软件开发人员,有着超过13年的开发经验,涉及的领域有通信,金融,零售,教育以及软件业等。他是Spring Framework的狂热拥护者,频繁的在当地local user groups讨论组和相关会议上演讲Spring,并且他的Blog上也有很多关于Spring的内容。出版的著作有: z Spring in Action, 2nd Edition, 2007 z XDoclet in Action, 2003 他的Blog是: z https://www.wendangku.net/doc/ff11061242.html, 所参与的项目: z Committer to XDoclet project; z Originator of Portlet and Spring modules for XDoclet 本手册主要是将分布于文档中的那些零散的配置文件部分统一成一个比较系统的整体。结合Spring文档一起查阅也许能节省你一些时间。不过,并不推荐你全部掌握;很多陌生的元素或标签只应用于特定场合。本手册英文版本可以在:https://www.wendangku.net/doc/ff11061242.html,下载。 Spring配置全书 作者Craig Walls 译者superleo 关于Spring的配置 Spring Framework总是不断的改变着Java企业开发的方向,它用一种松耦合的方式来配置和组装应用程序对象和业务对象,比以往的Java企业开发来的更加简洁。一旦你开发了基于Spring 的应用程序,在Spring上下文配置的那些资源简直就是唾手可得。 依赖注入是Spring容器的核心 尽管Spring Framework可以做很多事,但依赖注入却是Spring容器提供的最基本的功能。 任何稍微复杂一点的应用程序都至少由两个或两个以上的对象协作在一起,共同完成一些业务逻辑。以往的Java企业开发,每个对象都要自己去主动获得他们所引用(或依赖)的对象,才可正常运作。这将导致代码之间的紧耦合,难以测试。

Spring基础知识汇总

简介 框架由开发,2004年发布了框架的第一版。是一个从实际开发中抽取出来的框架,因此它完成了大量开发中的通用步骤,留给开发者的仅仅是与特定应用相关的部分,从而大大提高了企业应用的开发效率。 总结起来优点如下: ?低侵入式设计,代码的污染极低。 ?独立于各种应用服务器,基于框架的应用,可以真正实现,的承诺。 ?的容器降低了业务对象替换的复杂性,提高了组件之间的解耦。 ?的支持允许将一些通用任务如安全、事务、日志等进行集中式管理,从而提供了更好的复用。 ?的和提供了与第三方持久层框架的良好整合,并简化了底层的数据库访问。 ?的高度开放性,并不强制应用完全依赖于,开发者可自由选用框架的部分或全部。 框架的组成结构图如下所示: 的核心机制

管理 程序主要是通过容器来访问容器中的,是容器最常用的接口,该接口有如下两个实现类:?: 从类加载路径下搜索配置文件,并根据配置文件来创建容器。 ?: 从文件系统的相对路径或绝对路径下去搜索配置文件,并根据配置文件来创建容器。 使用 在等工具中,用户可以自建,然后把的包都放入其中,当然也可以将包直接放在项目的目录下,但是如果使用,在项目发布时,需要将用户库所引用的文件随应用一起发布,就是将所使用的复制到目录下,这是因为对于一个应用,部署应用时不会将用户库的文件复制到下,需要手动复制。 依赖注入 框架的核心功能有两个: ?容器作为超级大工厂,负责创建、管理所有的对象,这些对象被称为。 ?容器管理容器中之间的依赖关系,使用一种被称为"依赖注入"的方式来管理之间的依赖关系。 使用依赖注入,不仅可以为注入普通的属性值,还可以注入其他的引用。依赖注入是一种 优秀的解耦方式,其可以让以配置文件组织在一起,而不是以硬编码的方式耦合在一起。理解依赖注入 是第一个高度重视以配置文件来管理实例的协作关系的人,他给这种方式起了一个名字:控制反转(,)。后来为这种方式起了另一个名称:依赖注入(),因此不管是依赖注入,还是控制反转,其含义完全相同。当某个对象(调用者)需要调用另一个对象(被依赖对象)的方法时,在传统模式下通常有两种做法: 1.原始做法: 调用者主动创建被依赖对象,然后再调用被依赖对象的方法。 2.简单工厂模式: 调用者先找到被依赖对象的工厂,然后主动通过工厂去获取被依赖对象,最后再调 用被依赖对象的方法。

Spring基础知识汇总

Spring基础知识汇总简介年发布了框架的第一版。是一个从实际开发中抽取出来的框架,因此开发,2004框架由 它完成了大量开发中的通用步骤,留给开发者的仅仅是与特定应用相关的部分,从而大大提高了企业应用的开发效率。总结起来优点如下:?低侵入式设计,代码的污染极低。?的承诺。,独立于各种应用服务器,基于框架的应用,可以真正实现 ?的容器降低了业务对象替换的复杂性,提高了组件之间的解耦。?的支持允许将一些通用任务如安全、事务、日志等进行集中式管理,从而提供了更好的复用。?的和提供了与第三方持久层框架的良好整合,并简化了底层的数据库访问。?的高度开放性,并不强制应用完全依赖于,开发者可自由选用框架的部分或全部。框架的组成结构图如下所示: 的核心机制 1 / 10 Spring基础知识汇总管理程序主要是通过容器来访问容器中的,是容器最常用的接口,该接口有如下两个实现类:? : 从类加载路径下搜索配置文件,并根据配置文件来创建容器。? : 从文件系统的相对路径或绝对路径下去搜索配置文件,并根据配置文件来创建容器。 使用,然后把的包都放入其中,当然也可以将包直接放在项目的在等工具中,用户可以

自建,在项目发布时,需要将用户库所引用的文件随应用一起发布,目录下,但是如果使用所使用的复制到目录下,这是因为对于一个应用,部署应用时不会将用户库的文件就是将复制到 下,需要手动复制。依赖注入框架的核心功能有两个:?容器作为超级大工厂,负责创建、管理所有的对象,这些对象被称为。?的方式来管理之间的依赖关系。依赖注入容器管理容器中之间的依赖关系,使 用一种被称为使用依赖注入,不仅可以为注入普通的属性值,还可以注入其他的引用。依赖注入是一种优秀的解耦方式,其可以让以配置文件组织在一起,而不是以硬编码的方式耦合在一起。理解依赖注入是第一个高度重视以配置文件来管理实例的协作关系的人,他给这种方式起了一个名字:),因此不管是依赖注为这种方式起了另一个名称:依赖注入(,)。后来控制反转(入,还是控制反转,其含义完全相同。当某个对象(调用者)需要调用另一个对象(被依赖对象)的方法时,在传统模式下通常有两种做法:主动创建被依赖对象,然后再调用被依赖对象的方法。原始做法1. : 调用者通过工厂去获取被依赖对象,最后再调主动调用者先找到被依赖对象的工厂,然后简单工厂模式2. : 用被依赖对象的方法。2 / 10 基础知识汇总Spring二字,这必然会导致调用者与被依赖对象实现类的硬编码耦合,非常不利主动注意上面的接被动于项目升级的维护。使用框架之后,调用者无需主动获取被依赖对象,调用者只要受容器为调用者的成员变量赋值即可,由此可见,使用后,调用者获取被依赖对象的方式称之为控制反转。由原来的主动获取,变成了被动接受——所以 相当于为调另外从容器的角度来看,容器负责将被依赖对象赋值给调用者的成员变量——用者注入它依赖的实例,因此称之为依赖注入。 设值注入设值注入是指容器通过成员变量的方法来注入被依赖对象。这种注入方式简单、直观,因而在的依赖注入里大量使用。构造注入利用构造器来设置依赖关系的方式,被称为构造注入。通俗来说,就是驱动在底层以反射方式执行带指定参数的构造器,当执行带参数的构造器时,就可利用构造器参数对成员变这就是构造注入的本质。量执行初始化——两种注入方式的对比设值注入有如下优点:?与传统的的写法更相似,程序开发人员更容易理解、接受。通过方法设定依赖关系显得更加直观、自然。?对于复杂的依赖关系,如果采用构造注入,会导致构造器过于臃肿,难以阅读。在创建实例时,需要同时实例化其依赖的全部实例,因而导致性能下降。而使用设值注入,则能避免这些问题。?尤其在某些成员变量可选 的情况下,多参数的构造器更加笨重。构造注入优势如下:?构造注入可以在构造器中决定依赖关系的注入顺序,优先依赖的优先注入。?对于依赖关系无需变化的,构造注入更有用处。因为没有方法,所有的依赖关系全部在构造器内设定,无须担心后续的代码对依赖关系产生破坏。?依赖关系只能在构造器中设定,则只有组件的创建者才能 改变组件的依赖关系,对组件的调用者而言,组件内部的依赖关系完全透明,更符合高内聚的原则。注意: 建议采用设值注入为主,构造注入为辅的注入策略。对于依赖关系无须变化的注入,尽量采用构造注入;而其他依赖关系的注入,则考虑采用设值注入。3 / 10 Spring基础知识汇总容器中的对于开发者来说,开发者使用框架主要是做两件事:①开发;②配置。对于框架来说,它这就是所谓依赖注入——要做的就是根据配置文件来创建实例,并调用实例的方法完成的本质。容器中的作用域当通过容器创建一个实例时,不仅可以完成实例的实例化,还可以为指定特定的作用域。支持如下五种作用域:容器中,作用域的将只生成一个实例。1. : 单例模式,在整个方法获取作用域的时,都将产生一个新的实例。2.: 每次通过容器的()对于一次请求,作用域的将只生成一个实例,这意味着,在同一次请求内,程序每次请求该,得: 3. 到的总是同一个实例。只有在应用中使用时,该作用域才真正有效。对于一次会话,作用域的将只生成一个实例,这 意味着,在同一次会话内,程序每次请求该,得4. 到的总是同一个实例。只有在应用中使用时,该作用域才真正有效。 的时候有效,同样只在应用中有效。对应一个实例。在典型的情况下,仅在使用5. : 每个全局的 如果不指定的作用域,默认使用作用域。作用域的的创建、销毁代价比较大。而作用域的实例

spring配置文件头文件解读

xmlns:意思为域,为提供xml命名空间支持而添加的域。 首先,xml有格式,而为了spring的配置文件增加的节点能满足要求合法,所以必须引用校验该xml的格式文件。下面解释上面代码的每一行。 1. 第一行:初始化bean的格式文件地址 2. 第二行:辅助初始化bean 3. 第三行:Spring的p标签是基于xml Schema的配置方式, 目的是简化配置方式,如果不需要简化,可删除 4. 第四行:关于spring的上下文 5. 第五行:关于面向切面编程 6. 第六行:用来定义xmlschema的地址,也就是xml书写时需 要遵循的语法,两部分组成,前面是命名空间的名字,后面是 xsd(xmlschema)的地址。

Spring的XML配置文件的十二个最佳方法实践

spring是一个强大的Java应用框架,它广泛地应用于Java应用程序中,为Plain Old Java Objects(POJO)提供企业级服务。Spring利用依赖注入机制来简化工作,同时提高可测试性。其配置文件(通常是XML格式)中指定了 Spring bean、依赖性以及bean所需的服务。但是,这些XML配置文件既冗长又不实用。对于需要定义大量Spring bean的大型项目来说,它们难以阅读和管理。 在本文中,我将向您展示12种用于Spring XML配置的最佳实践。其中的一些实践与其说是最佳实践,倒不如说是必要实践。注意,其他因素(如域模型的设置)也可能影响XML的配置,但是本文重点研究XML配置的可读性和可管理性。 1。避免使用自动绑定(autowiring)功能 Spring 可以通过bean类的自省自动绑定依赖性,所以不必显式指明bean的属性和构造函数。Bean属性可以通过属性名称或类型匹配来实现自动绑定。构造函数通过类型匹配来实现自动绑定。甚至可以指定自动检测autowiring模式,它可以引导Spring选择一种适当的运行机制。先来看看下面的一个例子: Java代码 1. OrderService 类的属性名在容器中用于匹配bean实例。自动绑定可能会节省一些键入工作量并减少混乱。但是在现实项目中不应该使用这种方式,因为它牺牲了配置的可读性和可维护性。许多指南和介绍中大肆吹捧自动绑定是Spring的一项极好的特性,而没有提到这一特性所带来的牺牲。依我来看,这就像Spring 中的对象池(object-pooling),更大程度上只是宣传的噱头。对于精简XML 配置文件来说,它是一个好办法,但它实际上增加了复杂性,尤其是在运行包含大量类声明的项目时。虽然Spring允许混合使用自动绑定和显式绑定,但这会使XML配置更加晦涩难懂。 2.使用命名约定 该原则对于Java编码也一样适用。在项目中使用清晰的、描述性的、一致的命名约定将非常有利于开发人员理解XML配置。例如,对于bean ID,可以按照Java 类字段名约定来命名它。OrderServiceDAO实例的bean ID应该命名为orderServiceDAO。对于大型项目,可以在bean ID前面加上包名作为前缀。 3. 使用简洁形式 简洁形式避免了冗长,因为它将属性值和引用从子元素中移入属性中。例如下面的例子: Java代码 1.

Spring中加载xml配置文件的几种方式

项目中一个需求就是所有的功能都是插件的形式装入系统,这就需要利用Spring去动态加载某一位置下的配置文件,就总结了下Spring中加载xml配置文件的方式, xml是最常见的spring 应用系统配置源。Spring中的几种容器都支持使用xml装配bean,包括:XmlBeanFactory, ClassPathXmlApplicationContext, FileSystemXmlApplicationContext, XmlWebApplicationContext, ..... 一: XmlBeanFactory 引用资源 1.Resource cr = new ClassPathResource("applicationContext.xml"); BeanFactory bf=new XmlBeanFactory(cr); UserDao userDao = (UserDao)bf.getBean("userDao"); 二: ClassPathXmlApplicationContext 编译路径 使用ClassPathXmlApplicationContext对象获取,必须把applicationContext.xml放置到类的加载路径中,也就是Src下面 1.ApplicationContext factory=new ClassPathXmlApplicationContext("classpath:appcontext.xml"); // src目录下的 2.ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); UserDao userDao = (UserDao)context.getBean("userDao"); 3.ApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"applicationContext-oracle.xml","applicationContext.xml"}); UserDao userDao = (UserDao)context.getBean("userDao"); // src/conf 目录下的 4.ApplicationContext factory=new ClassPathXmlApplicationContext("conf/appcontext.xml"); 5.ApplicationContext factory=new ClassPathXmlApplicationContext("file:G:/Test/src/appcontext.xml"); 三: FileSystemXmlApplicationContext用文件系统

Spring基本配置及其常用方法

搭建spring的环境: 新建User Library:spring,引入spring的核心jar包: SPRING_HOME\dist\spring.jar spring核心jar包 SPRING_HOME \lib\log4j\log4j-1.2.14.jar 记录日志 SPRING_HOME \lib\jakarta-commons\commons-logging.jar 日志的抽象,日志的抽象,如果没有log4j则会借助commons-logging调用sun的记录日志的工具包,如果没有sun的和log4j的则它会调用自己的 在src目录下建立applicationContext.xml (可从SPRING_HOME\ samples\jpetstore\war\WEB-INF\目录下拷贝applicationContext.xml) 设置spring的xml标签的自动提示: Window-->Preferences-->MyEclipse Enterprise Workbench-->Files and Editors-->XML-->XML Catalog-->add-->location中添加Schema文件(SPRING_HOME\dist\resources\spring-beans-2.0.xsd)-->修改Key Type为Schema Location,将key的文件名设为:https://www.wendangku.net/doc/ff11061242.html,/schema/beans/spring-beans-2.0.xsd 提供log4j.properties配置文件: (G:\software_programming\Java\SSH\spring\spring-framework-2.0.8-with-dependencies\sp ring-framework-2.0.8\samples\jpetstore\war\WEB-INF\ log4j.properties) 定义bean标签的格式 DI方式从BeanFactory中获取对象: BeanFactory factory = new ClassPathXmlApplicationContext("applicationContext.xml"); //ApplicationContext factory = new ClassPathXmlApplicationContext("applicationContext.xml"); UserManager userManager = (UserManager)factory.getBean("userManager"); 定义公共配置为抽象bean: 其他bean继承抽象bean: 属性延迟初始化的配置方法:

spring+springmvc框架配置详解

1、基本概念 1.1、Spring spring是一个开源框架,Spring是于2003 年兴起的一个轻量级 的Java开发框架,由Rod Johnson 在其著作Expert One-On- One J2EE Development and Design中阐述的部分理念和原型衍生而来。它是为了解决企业应用开发的复杂性而创建的。Spring使用基本的JavaBean来完成以前只可能由EJB完成的事情。然而,Spring的用途 不仅限于服务器端的开发。从简单性、可测试性和松耦合的角度而言,任何Java应用都可以从Spring中受益。简单来说,Spring是一个轻量 级的控制反转(IoC)和面向切面(AOP)的容器框架。 1.2、SpringMVC Spring MVC属于SpringFrameWork的后续产品,已经融合在Spring Web Flow里面。Spring MVC 分离了控制器、模型对象、分派 器以及处理程序对象的角色,这种分离让它们更容易进行定制。 2.环境搭建详解 2.1引入相应的包 springMVC和spring包的结构发生了很大的变化,各个包都分开了,灵活,要求使用者更加深入的学习使用,当我们引入包的时候, 以少为原则,少的话可以根据报错来找到相应的包,如果过多的话, 包会报错异常的混乱,不容易分辨;sprinMVC和spring本身就是一家的,所以引入的包来说基本上和spring需要的架构包是一致的.

在WEB-INF文件夹下新建注解文件springMVC-servlet.xml文件