Bare Ben Spring (1)

Source: Internet
Author: User

Pom.xml

<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/maven-v4_0_0.xsd" ><modelversion >4.0.0</modelversion><groupid>com.test</groupid><artifactid>spring</artifactid ><packaging>war</packaging><version>0.0.1-snapshot</version><name>spring Maven Webapp</name><url>http://maven.apache.org</url><licenses><license><name> Apache License, Version 2.0</name><url>http://www.apache.org/licenses/license-2.0</url></ license></licenses><developers><developer><id>zzzz</id><name>caicai< /name><email>[email protected]</email><organization>shuwang Software, Inc.</ Organization><organizationurl>www.shuwang.info</organizationurl><roles><role> Project Lead</role></roles></developer></developers><properties><spring.version>4.2.3.release </spring.version></properties><dependencies><dependency><groupId> org.springframework</groupid><artifactid>spring-core</artifactid><version>${ spring.version}</version></dependency><dependency><groupid>org.springframework</ Groupid><artifactid>spring-beans</artifactid><version>${spring.version}</version> </dependency><dependency><groupId>org.springframework</groupId><artifactId> Spring-web</artifactid><version>${spring.version}</version></dependency><dependency ><groupid>org.springframework</groupid><artifactid>spring-context-support</artifactid ><version>${spring.version}</version></dependency><!--<dependency><groupid >org.springframework</groupid><artifactid>spring-aop</artifactid><version>${spring.version}</version></dependency>< dependency><groupid>org.springframework</groupid><artifactid>spring-expression</ Artifactid><version>${spring.version}</version></dependency>--></dependencies> <build><finalname>spring</finalname><sourcedirectory>src/main/java</sourcedirectory ><outputDirectory>target/classes</outputDirectory><resources><resource>< filtering>true</filtering><directory>src/main/resources</directory><includes>< include>**/application.properties</include><include>**/application.yml</include></ Includes></resource></resources></build></project>

Web. XML

<?xml version= "1.0" encoding= "UTF-8"? ><web-app xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns= "Http://java.sun.com/xml/ns/javaee" xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee/http Java.sun.com/xml/ns/javaee/web-app_3_0.xsd "id=" webapp_id "version=" 3.0 "> <display-name>spring</ display-name> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file& Gt;index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file> Default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file> default.jsp</welcome-file> </welcome-file-list> <context-param> <param-name> Contextconfiglocation</param-name> <param-value>WEB-INF/application.xml</param-value> </ Context-param> <listener> <description>springWebContextLoaderListener</description> < Listener-clAss>org.springframework.web.context.contextloaderlistener</listener-class> </listener></ Web-app>

Application.xml

<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:context= "Http://www.springframework.org/schema/context" Xsi:schemalocation= "http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/ spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/ Spring-context.xsd "><context:component-scan base-package=" Com.jiangchong.test "/></beans>

The JSP used for testing

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD "><% @page Import= "Org.springframework.web.context.support.WebApplicationContextUtils"%><% @page import= " Org.springframework.web.context.WebApplicationContext "%>

Testtest.class

Package Com.jiangchong.test;import Org.springframework.beans.factory.initializingbean;import Org.springframework.beans.factory.annotation.autowired;import Org.springframework.context.annotation.Bean; Import org.springframework.context.annotation.Configuration; @Configurationpublic class Testtest implements initializingbean{@AutowiredString get;public void Afterpropertiesset () throws Exception{system.out.println (get);} @Beanpublic testtest list () {return new Testtest ();}}

Test.class

Package Com.jiangchong.test;import Org.springframework.context.annotation.bean;import org.springframework.context.annotation.Configuration; @Configurationpublic class test{@Beanpublic String get () { return new String ("Test");}}

The Web container and spring are linked together, so I can not understand the wall.

Bare Ben Spring (1)

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.