Kawm khau raj caij nplooj ntoos hlav hauv 30 Feeb

Learn Spring Boot

Kawm khau raj caij nplooj ntoos hlav hauv 30 feeb

Txheej txheem cej luam

Caij nplooj ntoos hlav yog ib qhov hau uas tso cai rau koj ua raws li lub caij nplooj hlav thiab ntau lawm-npaj daim ntaub ntawv uas koj yuav khiav. Caij nplooj ntoos hlav pib raws li ib tug neeg quav tshuaj txhaj uas thaum ub, tab sis twb ho evolved rau lub moj khaum loj loj thaum lub sij hawm. Cov kev pab tseem ceeb txog Caij nplooj ntoos hlav khau raj yog nws tso cai rau koj ua los yog bootstrap enterprise daim ntaub ntawv uas yog npaj ntau lawm. Nws yog ib tug loj loj thiab ntau yam moj khaum uas koj ua tau ntau yam yooj yim rau koj txoj kev tsim ib daim ntawv thov cia. Hais tias, tseem muaj cov kev txwv ntawm lub moj khaum ob peb. Cov nyob rau ntawm qhov ntau le caag txiag yuav ruam tag thiab tus tsim tawm yuav muaj tsis tau txwv xaiv tau daim ntawv thov lub tsev. Lub hom phiaj tseem ceeb ntawm qhov tsab xov xwm no yog los muab kev pab ua hauj lwm nrog rau cov kev siv lub caij nplooj hlav khau raj.

Tus assumption no yog tias twb tau tsim ib daim ntawv thov lub caij nplooj hlav khau raj thiab nws khiav khiav. Khej hauv qab no qhia ib co kev taw qhia kev tswj ntawm ib daim ntawv thov lub caij nplooj hlav khau raj. Lwm assumption yog tias ib tug database uas muaj ib cov qauv ntaub ntawv hauv-nco khaws thiab siv tau nws ua ib qhov xov broker thiab ib cache.








Yuav tsum saib - caij nplooj ntoos hlav video tutorials

Video Tutorials – Caij nplooj ntoos hlav khau raj

Hloov dependencies

Ua ntej yuav siv lub caij nplooj ntoos hlav sib kho, hloov cov dependencies. Yog hais tias koj siv Maven, cov dependencies hauv qab no ntxiv rau hauv pom.xml.

<dependencies>

<!– … –>

<quav dej caws>

<groupId>org.springframework.Session</groupId>

<artifactId>caij nplooj ntoos hlav-qhib</artifactId>

<Version>1.3.0.TSO TAWM</Version>

</quav dej caws>

<quav dej caws>

<groupId>org.springframework.boot</groupId>

<artifactId>caij nplooj ntoos hlav-khau raj-oob khab -<lub npe database></artifactId>

</quav dej caws>

</dependencies>

Yuav tsum nyeem – Lawv muaj daim ntawv koj siv cov AngularJS thiab dhia tej ntaub ntawv JPA?








Configuring daim ntawv thov lub caij nplooj hlav khau raj

Lub caij nplooj ntoos hlav configuration tsim ib lim Servlet uas ntau qhov kev siv HttpSession xyoo uas yuav siv tau raws li lub caij nplooj ntoos hlav sib kho. Ua li no, ntxiv cov nram qab no configuration:

@Enable<databasename>HttpSession

tsev kawm HttpSessionConfig {

}

Nco ntsoov tias cov cov @Enable<databasename>HttpSession yog ib qho annotation uas tsim lub caij nplooj ntoos hlav kaus nrog lub npe springSessionRepositoryFilter. No lim tsim lub laj lim Servlet raws li hais dhau.

Koj yuav tau xav nyeem ntawv – Nrhiav kom paub cov kev pab Batch caij nplooj ntoos hlav

Configure cov kev twb kev txuas database

Tom qab cov kauj ruam saum toj no tiav, Caij nplooj ntoos hlav khau raj yeej tsim ib tug <databaseconnection>Hoobkas uas yog ib qhov zoo sib xws thaum lub caij nplooj ntoos hlav sib kho thiab tus tswv tsev lub zos. Yog tias koj ua haujlwm rau hauv ib cheeb tsam ntau lawm, koj yuav tsum nco ntsoov hloov cov configuration taw tes rau cov neeg rau zaub mov database. Ib qho piv txwv qhia nram qab no:

src/Main/Resources/Application.properties

caij nplooj ntoos hlav.<database>.party = localhost

caij nplooj ntoos hlav. <database>.lo lus zais = secret123

caij nplooj ntoos hlav. <database>.chaw nres nkoj = 6379

Initialize neeg rau zaub mov thawv

Nws muaj twb tau hais dhau ntawd lub caij nplooj hlav configuration, ua li saum, ib Servlet lim uas ntau qhov kev siv HttpSession xyoo uas yuav siv tau raws li lub caij nplooj ntoos hlav sib kho ua ib qho. Yuav pab lub taub lim servlet, caij nplooj ntoos hlav ua ntej tshaj yuav tsum thauj cov hoob kawm Config. Ntsig, qhov no yuav tsum ua kom ensured tias cov Servlet ntug (Nws yog Tomcat) utilizes lub springSessionRepositoryFilter kom muaj txhua thov tuaj ntawd yuav tsum tiav. Tom qab no cov kauj ruam no tag, Yog koj npaj txhij boot qauv daim ntawv thov lub caij nplooj hlav.



Yuav tsum nyeem – Dhia uas xeem coj – nws ua haujlwm li cas?

Khau raj qauv ntawv lub caij nplooj hlav

Koj yuav khiav daim qauv caij nplooj ntoos hlav tshiab uas muab rau qhov chaws thiab siv qhov hais kom ua los tiv thaiv kab mob nram qab no:

$ ./gradlew :kuaj:khau raj:bootRun

Nco ntsoov tias Gradle yog siv raws li ib lub cuab tam muaj. Tseem, khiav ntaub ntawv rau coj, koj yuav tsum mus nruab ib lub thwj version ntawm database rau ntawm qhov chaw ntawd thiab nws nrog qhov chaw nres nkoj vim khiav. Tom qab qhov no yuav ua li cas, cov qauv ntaub ntawv yuav tsum khiav ntawm http://localhost:<chaw nres nkoj>/

Teev nyob rau hauv cov ntaub ntawv

Tam sim no kom tau tus tsim nyog configuration, Nws yog lub sij hawm mus ntsuam xyuas cov ntaub ntawv los ntawm kev txiav kom nws. Rau hauv, sau kom tiav cov kauj ruam nram qab no:

  • Sau cov neeg siv lub npe.
  • Sau cov lo lus zais.
  • Nyem tus ID nkag mus khawm.

Tam sim no koj yuav tsum tau in thiaj li tso rau hauv cov ntaub ntawv. Tom qab koj tau nkag mus rau tus ID nkag mus peev xwm xws li tus neeg lub npe thiab lo lus zais, cov ntaub ntawv yog muab rau tus siv database thiab tsis yog hauv Tomcat lub HttpSession siv. Li ntawd, tsis txhob siv qhov kev siv HttpSession, lub qhov tseem ceeb yog nyob persisted hauv lub database. Raws li hais dhau, lub caij nplooj ntoos hlav qhib ntau xyoo tus HttpSession uas yuav siv ib lub database xaiv lub hom phiaj raws li. Tom qab cov SecurityContextPersistenceFilter rau lub caij nplooj ntoos hlav sib kho tej yam cov SecurityContext rau lub HttpSession, lub qhov tseem ceeb yog persisted hauv lub database.

Thaum cov kauj ruam saum toj no yog muab rau ua hauj lwm tom qab ib tsab ntawv teev npe coj mus kuaj rau khau raj caij nplooj ntoos hlav tau tsim, muaj ntau ntau lwm txoj kev uas ib tug qauv caij nplooj ntoos hlav khau raj ntawv yeej tswj. Lub moj khaum caij nplooj ntoos hlav yog lub moj khaum loj heev thiab nws muab txoj kev uas yuav ua hauj lwm thiab kev nthuav cov kev siv lub caij nplooj hlav khau raj heev heev.

Koj yuav tau xav nyeem ntawv – Kauj ruam los mus teem lub sij hawm pab raws qib kev siv moj khaum caij nplooj ntoos hlav








Coj daim ntawv

Peb muaj cov nram no 3 cov ntaub ntawv los yog tsim khiav ntaub ntawv rau. Ua ntej tshaj yog cov ntaub ntawv xws li thov kuas. Tus 2nd yog cov ntawv POM rau configuring taum. Tus 3lawm ib daim ntawv tseem ceeb thov yuav tsum sau qhia cov zis lawm.

Qhia 1: Xws li cov kev cai

pob com.techalpine.springframework;

ntshuam org.springframework.web.bind.annotation.RequestMapping;

ntshuam org.springframework.web.bind.annotation.RestController;

@RestController

tsev kawm BootController {

@RequestMapping(“/”)

pej xeem txoj hlua Performance index() {

rov qab mus “Txais tos lub caij nplooj hlav khau raj thov kom!”;

}

}

Qhia 2: Configuration chaws

<?xml version =”1.0″ encoding =”UTF-8″?>

<picture of Kathy 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>

<groupId>org.springfrmwork</groupId>

<artifactId>gs-caij nplooj ntoos hlav-khau raj-app</artifactId>

<Version>2.5.6</Version>

<niam txiv>

<groupId>org.springfrmwork.boot</groupId>

<artifactId>caij nplooj ntoos hlav khau raj-strtr-niam txiv</artifactId>

<Version>1.5.3.TSO TAWM</Version>

</niam txiv>

<dependencies>

<quav dej caws>

<groupId>org.springfrmwork.boot</groupId>

<artifactId>caij nplooj ntoos hlav-khau raj-strtr-web</artifactId>

</quav dej caws>

<quav dej caws>

<groupId>org.springfrmwork.boot</groupId>

<artifactId>caij nplooj ntoos hlav khau raj-strtr-niam txiv</artifactId>

</quav dej caws>

</dependencies>

<khoom>

<java.Version>1.8</java.Version>

</khoom>

<lawv muaj>

<plugins>

<plugin>

<groupId>org.springfrmwork.boot</groupId>

<artifactId>caij nplooj ntoos hlav-khau raj-mvn-plugin</artifactId>

</plugin>

</plugins>

</lawv muaj>

</yog ib qhov>

Qhia 3: Lub ntsiab ntawm daim ntawv thov kev pab cuam

pob com.techalpine.springframework;

ntshuam java.util.Arrays;

ntshuam org.springframework.boot.SpringApplication;

ntshuam org.springframework.boot.autoconfigure.SpringBootApplication;

ntshuam org.springframework.context.ApplicationContext;

@SpringBootApplication

tsev kawm BootApplication {

pej xeem tsis muaj dabtsis loj zoo li qub(Txoj hlua[] args) {

ApplicationContext actx = SpringApplication.run(BootApplication.class, args);

System.out.println(“Kuaj cov noob taum nkag rau thaum lub caij nplooj ntoos hlav khau raj:”);

Txoj hlua[] beanNms = actx.getBeanDefinitionNames();

Arrays.sort(beanNms);

rau (Txoj hlua beanNm : beanNms) {

System.out.println(beanNm);

}

}

}

Thaum cov kev pab cuam tseem ceeb no yog sau nws yuav ua tau tag nrho cov taum npe nkag rau los ntawm lub moj khaum caij nplooj ntoos hlav khau raj.

Yuav tsum nyeem – Tsev Restful web kev siv caij nplooj ntoos hlav?

Xaus

Thaum lub caij nplooj ntoos hlav khau raj rau nkawd muaj kev xaiv zoo los tsim kev caij nplooj ntoos hlav, yeej tsis tsis muaj nws cov drawbacks. Rau software developers, yog nws tsis yooj yim los ua raws li lub ntsiab ntawm quav tshuaj txhaj thiab IoC. Yog hais tias tus nqi tas nrho ntawm quav tshuaj txhaj thiab IoC no tsis to taub, ces tas nrho tej zaum txog lub caij nplooj ntoos hlav tsis tau yuav pom tau hais. Qhov xwm ntawm lub moj khaum caij nplooj ntoos hlav dynamic poses ib qho teeb meem loj loj. Ib txhia xav txog rau dynamism li ceev dhau lawm thiab unsettling heev. Thaum nws tuaj lub xeev, lub annotation-raws li lub caij nplooj hlav configuration tsi muaj ib yam dab tsi uas yog ib qho yooj yim mus use. Developers kuj yog tsis txaus siab ua vim yog quav tshuaj ntau heev vim cov quav tshuaj txhaj feature. Txawm li cas los, txhua yam yog, lub caij nplooj ntoos hlav khau raj yog muaj ntau yam kev bootstrap tsab ntawv.

Nyeem ntau tshaj cov khoom caij nplooj ntoos hlav – Caij nplooj ntoos hlav Archive

 


============================================= ============================================== Yuav zoo TechAlpine phau ntawv rau Amazon
============================================== ---------------------------------------------------------------- electrician ct chestnutelectric
error

Txaus siab rau qhov blog? Tshaj tawm lus thov :)

Follow by Email
LinkedIn
LinkedIn
Share