Skip to main content

Distributed Session - Web Application Edition

Demonstrates using a distributed session. For more usage, refer to dawdler-client-plug-session.

1. Download and Run​

Download the sample dawdler-tutorial.zip.

After extracting it, go into the session-single-web directory.

Start redis and configure session-redis.properties.

Run the main method of UserWebApplication.java.

@DawdlerBootApplication
public class UserWebApplication {
public static void main(String[] args) throws Throwable {
DawdlerWebApplication.run(UserWebApplication.class, args);
}
}

1.1 Configuration Files​

1.1.1 session-redis.properties​

The redis connection configuration can also be stored in the unified configuration center.

For related configuration, refer to dawdler-jedis-core.

1.2 Running as a Jar​

Run

mvn clean package

to get session-single-web-0.0.1-jdk25-SNAPSHOT-all.jar

Then run

java -jar session-single-web-0.0.1-jdk25-SNAPSHOT-all.jar
java -jar session-single-web-0.0.1-jdk25-SNAPSHOT-all.jar --server.port=8095

Start two java applications as above to verify the distributed session.

1.3 Verification​

Visit http://localhost:8085/user/set?userName=jackson.song&userId=233 in a browser to set the session object (the session object is set in the node on port 8085).

Visit http://localhost:8085/user/info and http://localhost:8095/user/info in a browser; both return the json information of the session object.