PackagePmisf.webservice.util;Importjavax.servlet.ServletContextEvent;ImportJavax.servlet.ServletContextListener;ImportOrg.springframework.context.ApplicationContext;ImportOrg.springframework.web.context.WebApplicationContext;Importorg.springframework.web.context.support.WebApplicationContextUtils; Public classSpringutilImplementsServletcontextlistener {Private StaticWebapplicationcontext Springcontext; PublicSpringutil () {Super(); } Public voidcontextinitialized (Servletcontextevent ev
In the project you often meet the need to use a bean instance in a spring container in listener or in a tool, because the bean cannot be used in a Stataic class.Describes one way:public class Springtool {public static Object getobjectfromapplication (HttpSession session,string beanname) { ServletContext servletcontext= Session.getservletcontext (); An instance of the
. *///in Web Apps, you can also access file resources by Servletcontextresource in a way that is relative to the Web App root//spring provides a resourceutils tool class that supports classpath: and File: "The address prefix that is capable of loading file resources from the specified address. File clsfile = Resourceutils.getfile ("Classpath:conf/file1.txt"); System.out.println (Clsfile.isfile ()); String H
Because of the need to access MongoDB, the local development environment is not directly connected to MongoDB and requires the use of 127.0.0.2 local IP proxy via SECURECRT. But after the program is deployed to the online production environment, it is possible to directly access MongoDB, so after the development of a program, always have to modify the MongoDB server IP to submit code, this is very inconvenient. privatestaticfinal"127.0.0.2";// private static final String PUBCHAT_HOST = "PROD
Brief introductionToday in the spring MVC source to see the following code, it feels quite interesting, here to recordThe Assert assertion tool class, typically used for data validation checks, typically writes the following code in Java programming:if (name = = NULL | | name.equls (")") {throw new IllegalArgumentException ("parameter wrong!");}It is not good to use manual detection of legality in all metho
More information can be accessed at Javamelody's official websiteI have been in the process of integration, there has been commonhibernatedao loading problem,
Also, depending on the official documentation, if your app conflicts with Monitoring-spring.xml or AOP, use the monitoring-spring-datasource.xml file instead Monitoring-spring.xml , this file contains only one datasource sending process and one example of Springdatasourcefactorybean.
Add these beans to the SPRING--MVC configuration file to use the @reponsebody annotations.Bean class="Org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"
p:ignoredefaultmodelonredirect="true" >
property name="Messageconverters">
list>
Bean class="Org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
list>
Property>
Bean>
Spr
Writing RowMapper is a tiring job when using spring JdbcTemplate. So I wrote a factory class rowmapperfactory that generates RowMapper based on the entity class to avoid writing RowMapper directly. Enumeration is not supported for rowmapperfactory.Here is rowmapperfactory:Import Org.springframework.jdbc.core.rowmapper;import Java.lang.reflect.method;import Java.sql.ResultSet;import Java.sql.sqlexception;import Java.util.hashmap;import Java.util.map;pu
File cfgfile = Resourceutils.getfile ("Classpath:test.txt");OrOrg.springframework.core.io.Resource Filerource = new Classpathresource ("Test.xml");Get file: Filerource.getfile ();Get file stream: Filerource.getinputstream ();Get to XML: Parse: Example:Document document = new Saxreader (). Read (Filerource.getfile ());Gets the node with ID test for the template node below myXMLelement element = (Element) Document.selectsinglenode ("/myxml/template[@id = ' test ']");Parse the XML and get the value
GoUsage scenario: In a static method, how to use the following injection;Private Itemmapper Itemmapper;@Component Public classtestutils {@AutowiredPrivateitemservice itemservice; @AutowiredPrivateItemmapper Itemmapper; Public Statictestutils testutils; @PostConstruct Public voidinit () {testutils= This; } //An example of how to use the service and Mapper interfaces in the Utils tool class, using the "testutils.xxx." Method. Public Static vo
/false.*/Public Boolean Getboolean (String Key) {String value = GetValue (key);if (value = = Null) {throw new Nosuchelementexception ();}return boolean.valueof (value);}/*** Remove the Boolean property, but the system property takes Precedence. returns the default value if it is null, or false if the content is not true/false.*/Public Boolean Getboolean (String key, boolean Defaultvalue) {String value = GetValue (key);return value! = null? Boolean.valueof (value): defaultvalue;}/*** Load multipl
View Eclipse version: Help–>about eclipse;1 shown.Access Http://spring.io/tools/sts/all, copy the online install URL address, do not download the zip file, copy the linkVersion URL address can copy the URL directly, do not need to click, click instead is download.4.6 Version: http://dist.springsource.com/release/TOOLS/update/e4.6/4.5 Version: HTTP://DIST.SPRINGSOURCE.COM/RELEASE/TOOLS/UPDATE/E4.5/After copying the URL, open eclipse–>help–>install new software, follow the prompts, next next, unti
Spring-boot Project Thermal Deployment Idea Tool:
(1), pom file introduction: All need to be true
(2), idea compiler set File→setting→compiler
(3) Idea setting
Shortcut keys Ctrl+alt+shift/
Check
Restart the project to take effect. Parental test is effective.
These days more busy looking at the previous project, found this spring under the Assert method, (previously used, but it seems to forget almost the * *)Org.springframework.util.Assert;The Assert assertion tool class, typically used for data legitimacy checks.It's usually written like this in the usual judgment.if (message== null | | message.equls ("")) {throw new IllegalArgumentException ("Incorrect input
The enhanced version increases the encryption string to 80 bits, and yes, the resulting hash values are not the same.Package Com.rapido.utils;import Org.springframework.security.crypto.password.passwordencoder;import org.springframework.security.crypto.password.standardpasswordencoder;/** * Spring Encryption tool Enhanced simplified version after Security3.1, using the SHA-256 algorithm, iterative 1024 time
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.