精华内容
下载资源
问答
  • 禁掉了with关键字。 普通模式eval作用域:eval在全局作用域,就是全局;eval在函数内部,就是局部作用域。在严格模式下,eval本身就是一个作用域。 为了代码安全this禁止指向全局对象。所以构造函数如果不通过new...
    1. 普通模式的变量、for循环中的变量可以不用var声明,严格模式必须使用var声明变量。
    2. 禁掉了with关键字。
    3. 普通模式eval的作用域:eval在全局作用域,就是全局;eval在函数内部,就是局部作用域。在严格模式下,eval本身就是一个作用域。
    4. 为了代码安全this禁止指向全局对象。所以构造函数如果不通过new实例化对象,那么就会直接报错,因为undefined无法设置属性。
    5. 为了让代码更安全,禁止在函数内部遍历调用栈。
    展开全文
  • BeanFactory 是 Spring IoC...Easier integration with Spring’s AOP features Message resource handling (for use in internationalization) Event publication Application-layer specific contexts such as the

    BeanFactory 是 Spring IoC 容器的底层实现;

    ApplicationContext 拥有 BeanFactory 的所有能力,还提供了

    • Easier integration with Spring’s AOP features
    • Message resource handling (for use in internationalization)
    • Event publication
    • Application-layer specific contexts such as the WebApplicationContext for use in web applications

    摘自:https://docs.spring.io/spring-framework/docs/5.2.2.RELEASE

    即更易集成 aop 特性、消息资源处理(国际化)、事件发布、应用程序层面特定的上下文如 WebApplicationContext。

     

    除了以上,细节上还包括:

    • BeanFactory 在启动的时候不会去实例化 bean,从容器中拿 bean 时才会去实例化;ApplicationContext 在启动时就把所有的 bean 全部实例化了
    • BeanPostProcessor、BeanFactoryPostProcessor 接口的注册:BeanFactory 需要手动注册,ApplicationContext 则是自动

    总之,ApplicationContext 是具备应用特性的 BeanFactory 超集。

     

    代码示例:

    pom

    <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>
    
        <parent>
            <groupId>constxiong</groupId>
            <artifactId>spring-study</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </parent>
    	
        <artifactId>003-spring-beanfactory-applicationcontext</artifactId>
    
        <properties>
            <spring-version>5.2.2.RELEASE</spring-version>
        </properties>
    
        <dependencies>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
                <version>${spring-version}</version>
            </dependency>
        </dependencies>
    
        <build>
    
        </build>
    </project>

     

    User.java

    package constxiong;
    
    public class User {
    	
    	private Integer id;
    	
    	private String name;
    
    	public Integer getId() {
    		return id;
    	}
    
    	public void setId(Integer id) {
    		this.id = id;
    	}
    
    	public String getName() {
    		return name;
    	}
    
    	public void setName(String name) {
    		this.name = name;
    	}
    
    	@Override
    	public String toString() {
    		return "User [id=" + id + ", name=" + name + "]";
    	}
    	
    }
    

     

    spring 配置文件

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    	
    	<bean class="constxiong.User">
    		<property name="id" value="1"/>
    		<property name="name" value="constxiong"/>
    	</bean>
    
    </beans>

     

    测试代码

    package constxiong;
    
    import org.springframework.beans.factory.support.DefaultListableBeanFactory;
    import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    /**
     * 测试 BeanFactory 与 ApplicationContext 的区别
     * @author ConstXiong
     */
    public class Test {
    	
    	public static void main(String[] args) {
    		String xmlPath = "META-INF/spring-beanfactory-applicationcontext.xml";
    		getBeanByBeanFactory(xmlPath);
    		getBeanByApplicationContext(xmlPath);
    	}
    
    	/**
    	 * 通过 ClassPathXmlApplicationContext 获取 bean
    	 */
    	private static void getBeanByApplicationContext(String xmlPath) {
    		ApplicationContext applicationContext = new ClassPathXmlApplicationContext(xmlPath);
    		User user = applicationContext.getBean(User.class);
    		System.out.println(user);
    	}
    
    	/**
    	 *  通过 DefaultListableBeanFactory 获取 bean
    	 */
    	private static void getBeanByBeanFactory(String xmlPath) {
    		DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
    		XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(beanFactory);
    		xmlReader.loadBeanDefinitions(xmlPath);
    		User user = beanFactory.getBean(User.class);
    		System.out.println(user);
    	}
    
    }
    


    说明:

    • 通过在 BeanFactory#getBean,ApplicationContext#getBean 方法这两行、User#setId 方法打上断点,可以看出 BeanFactory 是在调用 getBean 时初始化 User 这个 bean,ApplicationContext 是提前初始化完成的。
    • 通过查看源码可以看出,AbstractRefreshableApplicationContext 类间接继承了 BeanFactory 接口,同时持有 DefaultListableBeanFactory 对象 beanFactory;所有 BeanFactory 的能力都来自于 beanFactory。这点用到了装饰器设计模式。
    • ApplicationContext 对 BeanFactory 的能力的扩展体现在 AbstractApplicationContext#refresh 方法内。

     

     


    【Java学习资源】整理推荐

     

     


    【Java面试题与答案】整理推荐

    展开全文
  • CodeFileCodeBehind的区别 CodeBehind指定包含页关联的类的已编译文件的名称。该属性不能在运行时使用。Specifies the name of the compiled file that contains the class associated with the ...

    CodeFile与CodeBehind的区别  

     

    CodeBehind 
    指定包含与页关联的类的已编译文件的名称。该属性不能在运行时使用。
    Specifies the name of the compiled file that contains the class associated with the control. This attribute is not used at run time.

    指定包含与页关联的类的已编译文件的名称,编译完后所有cs中的代码打包进dll.该属性不能在运行时使用.提供此属性是为了与以前版本的 ASP.NET 的兼容,以实现代码隐藏功能。

    CodeFile 
    指定指向页引用的代码隐藏文件的路径。此属性与 Inherits 属性一起使用可以将代码隐藏源文件与网页相关联。此属性仅对编译的页有效。比如VS2005中新建一个网站你会发现编译比WEB应用程序慢很多,但是可以修改代码后不用整体编译刷新页面就可以看到效果.

    Specifies a path to the referenced code-behind file for the control. This attribute is used together with the Inherits attribute to associate a code-behind source file with a user control. The attribute is valid only for compiled controls.

     

    我这里碰到的情况就是,整个Web 项目被编译成了组件,但是 ASPX 页面有如下的定义: 
    <%@ Page CodeFile="***" Inherits="***" %> 
    这时候,ASP.net 就需要找 CodeFile 中指定的文件,以便动态编译,但是找不到,所以就报上述错误了。

    对于开发时,即 页面的逻辑代码 cs 文件存在的时候,下属两种写法都没有问题。
    <%@ Page Language="C#" AutoEventWireup="true" Codebehind="index.aspx.cs" Inherits="Community.IndexHomePage.index" %>

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="index.aspx.cs" Inherits="Community.IndexHomePage.index" %>

    但是部署到站点后,我们不会部署 cs 文件,这时候,后一种写法就会报找不到文件的错误了。除非你把 cs 也部署出去,否则就会报编译时错误,找不到文件...

    转载于:https://www.cnblogs.com/weicleer/archive/2012/11/06/2756691.html

    展开全文
  • A balanced attitude for Scala programmers Prefer vals, immutable objects, and methods without side effects. Reach for them first. Use vars, mutable objects, and methods with side effects when you
    A balanced attitude for Scala programmers
    Prefer vals, immutable objects, and methods without side effects.
    Reach for them first. Use vars, mutable objects, and methods with side
    effects when you have a specific need and justification for them.
    展开全文
  • SIMDMIMD的区别

    2020-11-23 12:25:49
    As we will see in Chapter 6, GPU Programming with Python, the advent of modern graphics processor unit (GPU), built with many SIMD embedded units has lead to a more widespread use of this ...
  • Java Javaw 的区别

    2010-10-27 18:04:02
    The javaw command is identical to java, except that with javaw there is no associated console window. Use javaw when you don't want a command prompt window to appear. The javaw launcher wil...
  • esim卡ms卡的区别With the launch of the Apple Watch 3, the term “eSIM” has been thrown around a lot. And now, Google’s Pixel 2 is the first phone to use this new technology, it’s time we take a ...
  • 一、组件版本二、提交方式三、运行原理四、分析过程五、致命区别六、总结 一、组件版本 调度系统:DolphinScheduler1.2.1 ... Please use master "yarn" with specified deploy mode instead. 这是因为你用了yarn-cl.
  • <p>Consider the following code which just prints all the ENV vars <pre><code>package main import ( ...<p>Sorry if this question is too stupid, I am just starting with Go </div>
  • The maintainers of gulp and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications....
  • JS中2个等号3个等号的区别

    千次阅读 2011-06-02 11:57:00
    ==是判断是否相等,值到前断时间 Visual Studio 2010上安装了一个关于JS压缩插件,而且该插件还有检察JS格式标准功能,所以常常在一保存JS文件后就会在错误列表中看到:Use '==='to compare with ".之类警告。...
  • 2、严格模式非严格模式不同 严格模式下,不允许使用with 严格模式下,不允许未声明变量赋值 严格模式下,argument.caller,argument.callee被禁用 严格模式下,一般函数调用,this指向n...
  • 之前安装过http2.2.21,后面换成版本2.2.19,然后就出现apache报错:Cannot use an external APR with the bundled APR-util 一般在第一次源码安装是没有问题,在版本变化情况下在次源码安装可能会遇到此问题...
  • 文章目录json.loads json.load区别json.load示例json.loads示例 json.loads json.load区别 stackoverflow上一个...I guess that the load() function must be used with a file object (I need thus to use a
  • <p>I'm guessing that #lang racket is a dialect of scheme with much more out of the box structures and common functions and perhaps would be more pedagogic. What are the perks a #lang racket against #...
  • I'm not sure whether I explained my problem well with these two approaches so let me refine my question. <p>I know that by using the <code>&</code> I will recieve a pointer instead of a value ...
  • apache2.0.xapache2.2.x在apr有很大区别,前者为依赖公用apr,后者依赖于自身apr。一般前者也就是2.0.x编译基本上没有apr方面问题。如果是后者也出现关于apr问题,则将安装前apr去除后,在编译apache2.2...
  • 时候启动报如下错:Error creating bean with name 'couponService': Bean with name 'couponService' has been injected into other beans [orderManagerServiceImpl,withdrawServiceImpl,orderServiceHelper,...
  • With that said, here is the .ini file I use:(keep in mind, it is a giagantic ini file, but the following are what is important that is NOT working.. <pre><code>SQL_TYPE=mysql HOST=localhost USER=...
  •  JDBC Thin for All Platforms classes12.jar (1,600,090 bytes) - for use with JDK 1.2 and JDK 1.3 在低级JDK版本1.21.3中使用驱动,虽然实际上在1.4,1.5中使用大部分情况也是OKclasses12_
  • apache2.0.xapache2.2.x在apr上有本质的区别,前者为依赖公用apr,后者依赖于自身的apr。一般前者也就是2.0.x的编译基本上没有apr方面的问题,除非,在编译前,安装了非2.0.x所需的apr,如果是这样,则需要将已经...
  • B-Tree Index CharacteristicsA B-tree index can be used for column comparisons in expressions that use the=,>,>=,In the first statement, only rows with'Patrick' <=key_col< 'Patricl'...
  • How does composer know what other files to get when I use the <code>create-project laravel/laravel</code> command and why do I only get the <code>vendor</code> folder when I do <code>require laravel/...
  • Koa is not bundled with any middleware. Installation Koa requires node v7.6.0 or higher for ES2015 and async function support. $ npm install koa Hello Koa const Koa = require('koa'); const app = new...
  • <p>The Post-Request is send by a JavaScript build with JQuery and looks like that: <pre><code>// type javaScript var formData = { field_a: "valueA", field_b: "", field_c: undefined }; $.ajax({ ...
  • apache2.0.xapache2.2.x在apr有很大区别,前者为依赖公用apr,后者依赖于自身apr。一般前者也就是2.0.x编译基本上没有apr方面问题。如果是后者也出现关于apr问题,则将安装前apr去除后,在编译apache2.2...

空空如也

空空如也

1 2 3 4 5
收藏数 89
精华内容 35
关键字:

use与with的区别