我进行了搜索和搜索,但没有找到任何说不可能的东西,也没有找到解释如何做的事情.
如果您有一个扩展的基本控制器,我理解请求映射方法也是继承的.
所以....
public abstract class BaseController
{
@RequestMapping(value="hello", method=RequestMethod.GET)
public String hello(Model model) {
return "hello-view;
}
Run Code Online (Sandbox Code Playgroud)
......像这样的控制器......
@Controller
@RequestMapping("/admin/")
public abstract class AdminController
{
....
}
Run Code Online (Sandbox Code Playgroud)
...将继承侦听/ admin/hello的方法,该方法返回hello-view.
这一切都很好.
但是如果我有一个重定向的BaseController方法怎么办:
public abstract class BaseController
{
@RequestMapping(value="hello", method=RequestMethod.POST)
public String hello(Model model) {
return "redirect:/success/;
}
Run Code Online (Sandbox Code Playgroud)
据我了解,重定向需要相对或绝对URL而不是视图名?
那么我的AdminController如何确保重定向发生在/ admin/success /?
BaseController方法如何获取AdminController上类级别@requestMapping的句柄?
这可能吗?
关于从spring启动应用程序构建war并在独立的servlet容器中运行它的一般问题.我似乎看起来似乎与Stack Overflow上的示例不一致.
这里的答案显示了几个月前我读到这样做的方式.我在这里读到了这个,但指南似乎已经改变了丢失实际的示例应用程序.
这里的"configure"方法引用了主要的Spring引导Application.class.
public class WebInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
}
Run Code Online (Sandbox Code Playgroud)
这里和这里也有这些帖子显示了引用SpringBootServletInitializer子类本身的"configure"方法.
public class BootStrap extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(BootStrap.class, args);
}
@Override
protected SpringApplicationBuilder configure(
SpringApplicationBuilder application) {
return application.sources(BootStrap.class);
}
}
Run Code Online (Sandbox Code Playgroud)
还有一个主要方法.
此外,https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples上的spring-boot-sample-traditional示例应用程序显示了"WAR包装"
public class WebConfig extends WebMvcConfigurerAdapter {.........
Run Code Online (Sandbox Code Playgroud)
我想知道选择这些不同的方式看似在春季靴子中实现相同的东西有问题吗?或者他们都同样工作,可以互换吗?
显示
RegistrationPolicy.FAIL_ON_EXISTING
Run Code Online (Sandbox Code Playgroud)
正在设置。
我们在独立的 tcserver 中使用 spring boot 创建的 WAR。新部署发生在旧版本取消部署之前,因此您可以部署多个版本。
我已经在使用
spring.jmx.default-domain=[app name]
Run Code Online (Sandbox Code Playgroud)
避免跨应用程序发生冲突……但是
我们看到类似的错误
UnableToRegisterMBeanException: Unable to register MBean with key 'dataSourceMBean'
nested exception is javax.management.InstanceAlreadyExistsException
Run Code Online (Sandbox Code Playgroud)
我们的数据源 Mbean 跨同一应用程序的不同版本。
我想设置一个
RegistrationPolicy.IGNORE_EXISTING
Run Code Online (Sandbox Code Playgroud)
我可以在维护 ObjectNamingStrategy 和 defaultDomain 的同时轻松做到这一点吗?虽然一点都不困难,但我希望我不必几乎覆盖所有 JmxAutoConfiguration?
可惜没有
spring.jmx.mbeanExporter.registrationPolicy
Run Code Online (Sandbox Code Playgroud)
弹簧靴属性
干杯
我正在使用具有以下pom依赖项的spring boot 1.3.0.RELEASE
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0.4</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)
我正在尝试使JPA工作,并且在我的application.properties中的以下内容都可以正常使用
# Connection url for the database
spring.datasource.url = jdbc:oracle:thin:@**********
# Username and password
spring.datasource.username = **********
spring.datasource.password = *********
Run Code Online (Sandbox Code Playgroud)
当我切换到tomcat-jdbc的完整dbcp配置时,如下所示:
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@**********
spring.datasource.username=*****
spring.datasource.password=*****
spring.datasource.initial-size=0
spring.datasource.max-active=10
spring.datasource.default-auto-commit=true
spring.datasource.default-transaction-isolation=2
spring.datasource.fair-queue=false
spring.datasource.jdbc-interceptors=ConnectionState;StatementFinalizer;ResetAbandonedTimer"
spring.datasource.jmx-enabled=true
spring.datasource.log-abandoned=true
spring.datasource.max-idle=1
spring.datasource.max-wait=30000
spring.datasource.min-evictable-idle-time-millis=60000
spring.datasource.min-idle=1
spring.datasource.remove-abandoned=true
spring.datasource.remove-abandoned-timeout=300
spring.datasource.test-on-borrow=true
spring.datasource.test-on-return=false
spring.datasource.test-while-idle=false
spring.datasource.time-between-eviction-runs-millis=10000
spring.datasource.use-equals=false
spring.datasource.validation-interval=60000 …Run Code Online (Sandbox Code Playgroud)