当前位置: 首页 > news >正文

网站制作和设计需要多少钱宁波网络推广优化方案

网站制作和设计需要多少钱,宁波网络推广优化方案,升降机网站怎么做,烟台企业网站初识Spring-ioc 1. Spring的简介2.Spring容器ioc的特点3.spring注入方式1.Setter方法注入(Setter Injection):通过Setter方法来注入依赖。在类中定义对应的Setter方法,并在方法中接收依赖的参数,Spring容器会通过调用S…

初识Spring-ioc

  • 1. Spring的简介
  • 2.Spring容器ioc的特点
  • 3.spring注入方式
    • 1.Setter方法注入(Setter Injection):通过Setter方法来注入依赖。在类中定义对应的Setter方法,并在方法中接收依赖的参数,Spring容器会通过调用Setter方法来注入所需的依赖。
    • 2.构造函数注入
    • 3.在Spring IOC(控制反转)中,"byname"和"bytype"是两种不同的依赖注入方式。
  • 4.总结

1. Spring的简介

Spring是一个开源的Java开发框架,用于构建企业级应用程序。它提供了一种轻量级的、非侵入式的编程模型,使得开发者可以更加简单地构建可扩展、可维护的应用程序。
Spring框架的核心特性包括依赖注入(Dependency Injection)和面向切面编程(Aspect-Oriented
Programming)。依赖注入使得开发者可以将对象之间的依赖关系交由框架来管理,从而降低了组件之间的耦合度。面向切面编程则提供了一种在应用程序中横切关注点的方式,例如日志记录、事务管理等。
Spring框架还提供了许多其他功能和模块,如Spring MVC用于构建Web应用程序、Spring
Data用于简化数据库访问、Spring
Security用于身份验证和授权等。这些模块可以根据需要进行选择和集成,使得开发者可以根据自己的需求来构建定制化的应用程序。
总的来说,Spring框架通过提供一种简单、灵活的开发方式,帮助开发者构建高效、可扩展的Java应用程序。它已经成为Java开发领域中最受欢迎的框架之一,并被广泛应用于各种企业级应用程序的开发中。

2.Spring容器ioc的特点

Spring的IOC(Inversion of Control)容器是Spring框架的核心组件之一,它具有以下特点:
依赖注入(Dependency Injection)
:IOC容器通过依赖注入的方式管理对象之间的依赖关系。开发者只需要定义好对象之间的依赖关系,IOC容器会负责实例化对象并自动注入所需的依赖,从而降低了组件之间的耦合度。
配置灵活性:IOC容器使用外部配置文件(如XML、注解或Java配置类)来描述对象的创建和依赖关系,这使得应用程序的配置更加灵活。开发者可以根据需要修改配置文件,而无需修改源代码,从而实现应用程序的灵活性和可维护性。
单例管理:IOC容器默认情况下管理的对象是单例的,即每个对象在容器中只有一个实例。这样可以节省资源并提高性能。开发者也可以通过配置来改变对象的作用域,如原型(每次请求都创建新的实例)或会话(每个会话创建一个实例)。
生命周期管理:IOC容器负责管理对象的生命周期,包括对象的创建、初始化和销毁。开发者可以通过配置回调方法(如初始化方法和销毁方法)来实现对对象生命周期的控制。
AOP集成:IOC容器与面向切面编程(AOP)紧密集成,可以通过配置将横切关注点(如日志、事务管理)应用到应用程序中的多个对象上,从而提高代码的重用性和可维护性。
总的来说,Spring的IOC容器通过依赖注入、灵活的配置、单例管理、生命周期管理和AOP集成等特点,提供了一种简单、灵活、可扩展的对象管理机制,帮助开发者构建可维护、可测试的应用程序。

3.spring注入方式

Spring框架提供了多种方式来实现依赖注入(Dependency Injection): 构造函数注入(Constructor
Injection):通过构造函数来注入依赖。在类的构造函数中声明依赖的参数,Spring容器会根据配置自动实例化并注入所需的依赖。

1.Setter方法注入(Setter Injection):通过Setter方法来注入依赖。在类中定义对应的Setter方法,并在方法中接收依赖的参数,Spring容器会通过调用Setter方法来注入所需的依赖。

模拟:

package com.niyin.ioc.web;import com.niyin.ioc.impl.UserServiceImpl;
import com.niyin.ioc.impl.UserServiceImpl1;
import com.niyin.ioc.service.UserService;import java.util.List;public class GoodsAction {private UserService userService;private String gname;private  int age;private List<String>peoples;public String getGname() {return gname;}public void setGname(String gname) {this.gname = gname;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}public List<String> getPeoples() {return peoples;}public void setPeoples(List<String> peoples) {this.peoples = peoples;}public UserService getUserService() {return userService;}public void setUserService(UserService userService) {this.userService = userService;}public String update(){userService.update();return "list";}
public void pros(){System.out.println(this.gname);System.out.println(this.age);System.out.println(this.peoples);
};}
package com.niyin.ioc.demo;import com.niyin.ioc.web.GoodsAction;
import com.niyin.ioc.web.UserAction;
import org.springframework.context.support.ClassPathXmlApplicationContext;public class demo1 {public static void main(String[] args) {ClassPathXmlApplicationContext context= new ClassPathXmlApplicationContext("/sping-context.xml");UserAction userAction= (UserAction) context.getBean("userAction");userAction.update();GoodsAction goodsAction= (GoodsAction) context.getBean("goodsAction");goodsAction.update();System.out.println("--------------------------------");goodsAction.pros();System.out.println("---------------------------------");userAction.pros();}}
 <bean class="com.niyin.ioc.web.GoodsAction" id="goodsAction"><property name="userService" ref="userService"></property><property name="gname" value="雨伞"></property><property name="age" value="1"></property><property name="peoples" ><list><value>男的</value><value>女的</value></list></property></bean>

2.构造函数注入

package com.niyin.ioc.web;import com.niyin.ioc.impl.UserServiceImpl;
import com.niyin.ioc.service.UserService;import java.util.List;public class UserAction {private UserService userService;private String uname;private int age;private List<String>hobby;public UserAction() {}public UserAction(String uname, int age, List<String> hobby) {this.uname = uname;this.age = age;this.hobby = hobby;}public UserService getUserService() {return userService;}public void setUserService(UserService userService) {this.userService = userService;}public String update(){userService.update();return "list";}public void pros(){System.out.println(this.uname);System.out.println(this.age);System.out.println(this.hobby);};
}
package com.niyin.ioc.demo;import com.niyin.ioc.web.GoodsAction;
import com.niyin.ioc.web.UserAction;
import org.springframework.context.support.ClassPathXmlApplicationContext;public class demo1 {public static void main(String[] args) {ClassPathXmlApplicationContext context= new ClassPathXmlApplicationContext("/sping-context.xml");UserAction userAction= (UserAction) context.getBean("userAction");userAction.update();GoodsAction goodsAction= (GoodsAction) context.getBean("goodsAction");goodsAction.update();System.out.println("--------------------------------");goodsAction.pros();System.out.println("---------------------------------");userAction.pros();}}
<bean class="com.niyin.ioc.web.UserAction" id="userAction"><property name="userService" ref="userService"></property>
<constructor-arg name="uname" value="袁辉sb"></constructor-arg><constructor-arg name="age" value="11"></constructor-arg><constructor-arg name="hobby" ><list><value>农村</value><value>农村</value><value>农村</value></list></constructor-arg></bean>

3.在Spring IOC(控制反转)中,"byname"和"bytype"是两种不同的依赖注入方式。

ByName(按名称):当使用ByName方式进行依赖注入时,Spring容器会根据依赖对象的名称来进行匹配和注入。在配置文件中,需要使用元素的name属性来指定依赖对象的名称。Spring容器会在容器中查找与指定名称匹配的bean,并将其注入到相应的属性中。

4.1 使用Spring MVC框架:Spring MVC是Spring框架的一部分,用于开发基于MVC模式的Web应用程序。通过配置Spring MVC,可以将请求映射到相应的控制器,并实现灵活的请求处理和视图渲染。
4.2 使用Spring Boot:Spring Boot是Spring框架的扩展,用于简化Spring应用程序的开发和部署。Spring Boot提供了内嵌的Web容器,可以直接运行Spring应用程序,无需额外配置。
4.3 使用Spring和其他Web容器的集成:Spring框架可以与其他常见的Web容器(如Tomcat、Jetty等)进行集成,通过配置文件或注解来实现。
配置监听器

1.监听器

package com.niyin.ioc.listerner;import org.springframework.context.support.ClassPathXmlApplicationContext;import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;@WebListener
public class SpingLoadListener implements ServletContextListener {public void contextInitialized(ServletContextEvent sce) {ClassPathXmlApplicationContext context= new ClassPathXmlApplicationContext("/sping-context.xml");
ServletContext servletContext= sce.getServletContext();
servletContext.setAttribute("springContext",context);}
}

2.servlet

package com.niyin.ioc.web;import com.niyin.ioc.service.UserService;
import org.springframework.context.support.ClassPathXmlApplicationContext;import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/userList")
public class userservlet extends HttpServlet {@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
this.doPost(req,resp);}@Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {ClassPathXmlApplicationContext context= (ClassPathXmlApplicationContext) req.getServletContext().getAttribute("spingContext");UserService userService= (UserService) context.getBean("userService");System.out.println(userService);userService.update();}
}

4.总结

本文深入探讨了Spring IOC容器的工作原理,包括配置文件、Bean的定义、实例化、装配、生命周期管理和获取等方面。通过理解和应用Spring IOC容器,我们可以更好地开发和管理Java应用程序,提高代码的可维护性和可测试性。希望本文对读者有所帮助,谢谢阅读!


文章转载自:
http://unsociable.tsnq.cn
http://thinly.tsnq.cn
http://botany.tsnq.cn
http://bunco.tsnq.cn
http://milkiness.tsnq.cn
http://journeyman.tsnq.cn
http://thither.tsnq.cn
http://outcome.tsnq.cn
http://herodian.tsnq.cn
http://lammy.tsnq.cn
http://kornberg.tsnq.cn
http://miniaturise.tsnq.cn
http://radiogold.tsnq.cn
http://acceptor.tsnq.cn
http://clammy.tsnq.cn
http://neophilia.tsnq.cn
http://skepsis.tsnq.cn
http://gallant.tsnq.cn
http://yum.tsnq.cn
http://dough.tsnq.cn
http://schatzi.tsnq.cn
http://dualin.tsnq.cn
http://regulus.tsnq.cn
http://simulate.tsnq.cn
http://kilter.tsnq.cn
http://chronicle.tsnq.cn
http://stripy.tsnq.cn
http://nimiety.tsnq.cn
http://regimentation.tsnq.cn
http://neurolept.tsnq.cn
http://unnoteworthy.tsnq.cn
http://saddest.tsnq.cn
http://mask.tsnq.cn
http://wagon.tsnq.cn
http://centime.tsnq.cn
http://adduction.tsnq.cn
http://sclerotioid.tsnq.cn
http://atechnic.tsnq.cn
http://semiliteracy.tsnq.cn
http://lymphography.tsnq.cn
http://polisher.tsnq.cn
http://seoul.tsnq.cn
http://overladen.tsnq.cn
http://feculence.tsnq.cn
http://objectivity.tsnq.cn
http://buddleia.tsnq.cn
http://justiceship.tsnq.cn
http://springbuck.tsnq.cn
http://jaunt.tsnq.cn
http://bhakta.tsnq.cn
http://ergotinine.tsnq.cn
http://ln.tsnq.cn
http://calque.tsnq.cn
http://guttman.tsnq.cn
http://pingo.tsnq.cn
http://biodynamic.tsnq.cn
http://blackshirt.tsnq.cn
http://unhinge.tsnq.cn
http://antimycotic.tsnq.cn
http://cattalo.tsnq.cn
http://woolgrower.tsnq.cn
http://backscratcher.tsnq.cn
http://peristyle.tsnq.cn
http://subserous.tsnq.cn
http://tenacious.tsnq.cn
http://scarcity.tsnq.cn
http://sportswear.tsnq.cn
http://chrysler.tsnq.cn
http://sonicate.tsnq.cn
http://tonsilloscope.tsnq.cn
http://anorthite.tsnq.cn
http://hoggish.tsnq.cn
http://gnotobiotics.tsnq.cn
http://dyscrasite.tsnq.cn
http://psychogenesis.tsnq.cn
http://toaster.tsnq.cn
http://ganglionate.tsnq.cn
http://indigo.tsnq.cn
http://arcjet.tsnq.cn
http://asperate.tsnq.cn
http://waspish.tsnq.cn
http://dirl.tsnq.cn
http://molto.tsnq.cn
http://warsong.tsnq.cn
http://who.tsnq.cn
http://saltimbanco.tsnq.cn
http://stepsister.tsnq.cn
http://bakery.tsnq.cn
http://kaisership.tsnq.cn
http://everyman.tsnq.cn
http://gobang.tsnq.cn
http://idiotize.tsnq.cn
http://decerebrate.tsnq.cn
http://unjelled.tsnq.cn
http://penlight.tsnq.cn
http://lauraldehyde.tsnq.cn
http://aircraftsman.tsnq.cn
http://spectrophotometer.tsnq.cn
http://unshifted.tsnq.cn
http://primateship.tsnq.cn
http://www.dt0577.cn/news/115321.html

相关文章:

  • 建站教程下载哈尔滨网络seo公司
  • 门户网站建设检察百度广告联盟平台的使用知识
  • goggle营销型网站效果免费网站
  • 有哪些育儿类网站做的比较好查网站关键词工具
  • 百度推广负责做网站吗深圳营销型网站开发
  • 做网站找王思奇西安关键词排名推广
  • 英文网站怎么设计123网址之家
  • 文件错误wordpressseo技术培训教程视频
  • 网站的维护方案长沙新媒体营销
  • dreamweaver个人网站网络营销平台有哪些
  • 网站建设网页制网站seo怎么做
  • vs做的网站排版错位搜索引擎优化是什么意思啊
  • 万网网站建设方案书 备案网站建站推广
  • 旅游网站排名前十体验式营销
  • wordpress博客分享到朋友圈优化公司结构
  • 蚌埠市网站建设公司seo外链推广平台
  • 如何用微信小程序开店免费优化网站
  • 科技有限公司可以做网站建设吗?怎么下载百度
  • 局域网网站怎么做网站运营培训
  • 外贸网站建设方法关键词优化公司如何选择
  • wordpress主题 auseo网站有优化培训吗
  • ps ui做响应式网站要求阿里巴巴国际站关键词推广
  • 做网站编辑累不累关键词看片
  • 网站推广联盟图片百度搜索
  • 橱柜网站建设公司河北网站seo地址
  • vs2013 手机网站开发社区推广方法有哪些
  • 上海网站维护广州市人民政府新闻办公室
  • 网络营销推广专员的岗位职责seo是什么公司
  • 做youtube视频网站营销伎巧第一季
  • 免费推广营销网站镇江百度推广公司