-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
60 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 54 additions & 44 deletions
98
Test20-Thymeleaf1/src/main/java/org/sang/Test20Thymeleaf1Application.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,71 @@ | ||
package org.sang; | ||
|
||
import org.apache.catalina.Context; | ||
import org.apache.catalina.connector.Connector; | ||
import org.apache.tomcat.util.descriptor.web.SecurityCollection; | ||
import org.apache.tomcat.util.descriptor.web.SecurityConstraint; | ||
import org.sang.bean.Person; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; | ||
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Controller | ||
@SpringBootApplication | ||
public class Test20Thymeleaf1Application { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(Test20Thymeleaf1Application.class, args); | ||
} | ||
public static void main(String[] args) { | ||
SpringApplication.run(Test20Thymeleaf1Application.class, args); | ||
} | ||
|
||
@RequestMapping("/") | ||
public String index(Model model) { | ||
Person single = new Person("aa", 11); | ||
List<Person> people = new ArrayList<>(); | ||
Person p1 = new Person("zhangsan", 11); | ||
Person p2 = new Person("lisi", 22); | ||
Person p3 = new Person("wangwu", 33); | ||
people.add(p1); | ||
people.add(p2); | ||
people.add(p3); | ||
model.addAttribute("singlePerson", single); | ||
model.addAttribute("people", people); | ||
return "index"; | ||
} | ||
|
||
@Bean | ||
public EmbeddedServletContainerFactory servletContainer() { | ||
TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory() { | ||
@Override | ||
protected void postProcessContext(Context context) { | ||
SecurityConstraint constraint = new SecurityConstraint(); | ||
constraint.setUserConstraint("CONFIDENTIAL"); | ||
SecurityCollection collection = new SecurityCollection(); | ||
collection.addPattern("/*"); | ||
constraint.addCollection(collection); | ||
context.addConstraint(constraint); | ||
} | ||
}; | ||
tomcat.addAdditionalTomcatConnectors(httpConnector()); | ||
return tomcat; | ||
} | ||
|
||
@RequestMapping("/") | ||
public String index(Model model) { | ||
Person single = new Person("aa", 11); | ||
List<Person> people = new ArrayList<>(); | ||
Person p1 = new Person("zhangsan", 11); | ||
Person p2 = new Person("lisi", 22); | ||
Person p3 = new Person("wangwu", 33); | ||
people.add(p1); | ||
people.add(p2); | ||
people.add(p3); | ||
model.addAttribute("singlePerson", single); | ||
model.addAttribute("people", people); | ||
return "index"; | ||
} | ||
// @Bean | ||
// public EmbeddedServletContainerFactory servletContainer(){ | ||
// TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory(){ | ||
// @Override | ||
This comment has been minimized.
Sorry, something went wrong. |
||
// protected void postProcessContext(Context context) { | ||
// SecurityConstraint constraint = new SecurityConstraint(); | ||
This comment has been minimized.
Sorry, something went wrong. |
||
// constraint.setUserConstraint("CONFIDENTIAL"); | ||
// SecurityCollection collection = new SecurityCollection(); | ||
// collection.addPattern("/*"); | ||
// constraint.addCollection(collection); | ||
// context.addConstraint(constraint); | ||
// } | ||
// }; | ||
// tomcat.addAdditionalTomcatConnectors(httpConnector()); | ||
// return tomcat; | ||
// } | ||
// @Bean | ||
// public Connector httpConnector(){ | ||
// Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); | ||
// connector.setScheme("http"); | ||
// //Connector监听的http的端口号 | ||
// connector.setPort(8081); | ||
// connector.setSecure(false); | ||
// //监听到http的端口号后转向到的https的端口号 | ||
// connector.setRedirectPort(8080); | ||
// return connector; | ||
// } | ||
@Bean | ||
public Connector httpConnector() { | ||
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol"); | ||
connector.setScheme("http"); | ||
//Connector监听的http的端口号 | ||
connector.setPort(8080); | ||
connector.setSecure(false); | ||
//监听到http的端口号后转向到的https的端口号 | ||
connector.setRedirectPort(8443); | ||
return connector; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
...