Tag: spring mvc

Java spring框架 – 如何设置内容类型?

我有一个弹簧动作,我从控制器渲染一些json,在它返回内容类型’text / plain; charset = ISO-8859-1’的那一刻。 如何将其更改为’application / json’? 谢谢乔恩

Spring MVC控制器HTTP GET查询参数

如何在没有注释的情况下创建和连接将根据查询参数执行操作的控制器? 所以也许我有一个页面上有一个项目列表,每个页面都是像“edititem.htm?id = 5”这样的链接。 当用户点击链接时,我希望控制器加载“第5项”并将其传递给我的编辑表单。 我很抱歉问这么愚蠢的问题,但由于某种原因,我找不到任何在线这样做的例子。

spring-nullpointerexception-无法在无注释类中访问自动连接的带注释的服务(或dao)

我有这个问题,我无法解决。 从我的@Controller ,我可以轻松访问我的自动assembly的@Service类并使用它没有问题。 但是当我从没有注释的单独类中执行此操作时,它会给我一个NullPointerException 。 我的控制器(工程) – @Controller public class UserController { @Autowired UserService userService;… 我的单独Java类(不工作) – public final class UsersManagementUtil { @Autowired UserService userService; 要么 @Autowired UserDao userDao; userService或userDao始终为null! 只是尝试其中任何一个工作。 我的组件扫描设置具有用于扫描的根级别包,因此应该没问题。 我的servlet上下文 – / .jsp 0 orion.core.models.Question orion.core.models.User orion.core.models.Space orion.core.models.UserSkill orion.core.models.Question orion.core.models.Rating ${hibernate.dialect} ${hibernate.show_sql} ${hibernate.hbm2ddl.auto} 任何线索?

Spring Condition无法从属性文件中读取值

我正在尝试实现Spring Condition org.springframework.context.annotation.Condition ,如下所示: public class APIScanningDecisionMaker implements Condition { @Override public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) { // Not able to read the property “swagger.scanner.can.run”. It is always NULL. String canRunFlagInStr = context.getEnvironment().getProperty(“swagger.scanner.can.run”); // Ignore the rest of the code. } } 但是,如上面的代码所示,当我读取属性“swagger.scanner.can.run”时,它始终为NULL。 在我的属性文件中,我将其设置为“swagger.scanner.can.run = false”。 我也尝试使用@Value(“${swagger.scanner.can.run}”)但即便返回NULL。 当我在这个方法中进行调试时,我可以看到它正被调用。 仅仅为了完成我使用APIScanningDecisionMaker如下: @Configuration @EnableSwagger @Conditional(APIScanningDecisionMaker.class) public class […]

将Spring @RequestMapping注释自动记录到一个位置?

Javadoc非常适合扫描所有源文件并创建HTML页面来查看它。 我想知道是否有一个类似的工具可以通过所有的Spring控制器并收集所有已经使用@RequestMapping注释的方法,并生成一个列出它们的HTML页面。 类似于伪站点地图,供开发人员确保控制器的唯一性和标准化。 如果已经在别处问过这个问题,我道歉。 我无法想出一套适当的搜索条件来提供有用的结果。

Spring 3.2 DeferredResult – 如何设置错误响应的状态代码?

Spring Web 3.2附带了一个用于异步请求处理的DeferredResult类。 它有一个setErrorResult用于在出现问题时提供备用响应,但没有提供http错误代码的选项。 当然必须能够控制失败请求的http响应代码。我如何使用新的Spring api做到这一点?

请求方法“POST”不受支持

根据这里的Spring文档: 虽然HTTP定义了这四种方法,但HTML只支持两种:GET和POST。 幸运的是,有两种可能的解决方法:您可以使用JavaScript来执行PUT或DELETE,或者只使用“real”方法作为附加参数进行POST(在HTML表单中建模为隐藏输入字段)。 他们已经完成了后者,并且可以使用以下spring MVC表单标签来实现: 问题是,当我单击“删除”时,我的页面会抛出以下错误: HTTP Status 405 – Request method ‘POST’ not supported 我将org.springframework.web的调试级别更改为debug并找到以下消息: DEBUG AnnotationMethodHandlerExceptionResolver – Resolving exception from handler [foo.bar.MessageForm@da9246]: org.springframework.web.HttpRequestMethodNotSupportedException: Request method ‘POST’ not supported 我使用RestClient和DELETE方法,并按预期调用该方法。 我在这做错了什么?

Thymeleaf:用替换换行符

我有一个字段( ),可能包含换行符,我想用它们的HTML替换它们: 。 我怎样才能做到这一点? 我正在使用Thymeleaf 2.1.4.RELEASE。

通过ServletContextListener中的SimpMessagingTemplate向所有客户端发送消息

我正在使用Spring框架,我有一个工作的websocket控制器,如下所示: @Controller public class GreetingController { @MessageMapping(“/hello”) @SendTo(“/topic/greetings”) public Greeting greeting(HelloMessage message) throws InterruptedException { return new Greeting(“Hello, ” + message.getName() + “!”); } } 我也有这个配置: @Configuration @EnableWebSocketMessageBroker public class HelloWebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer { @Override public void configureMessageBroker(MessageBrokerRegistry config) { config.enableSimpleBroker(“/topic”); config.setApplicationDestinationPrefixes(“/app”); } public void registerStompEndpoints(StompEndpointRegistry registry) { registry.addEndpoint(“/hello”).withSockJS(); } } 那部分效果很好! 我可以使用Stomp.js在两个或多个浏览器之间成功发送和接收消息。 这是不起作用的部分。 我已经实现了一个ServletContextListener […]

Spring 3.1:DataSource未自动连接到@Configuration类

我正在使用Spring MVC 3.1.0M2并尝试将我的配置移动到java bean。 但我遇到以下错误: 2011-09-14 18:43:42.301:警告:/:不可用org.springframework.beans.factory.BeanCreationException:创建名为’org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration#0’的bean时出错:注入自动连接的依赖项失败; 嵌套exception是org.springframework.beans.factory.BeanCreationException:无法自动assembly方法:void org.springframework.transaction.annotation.AbstractTransactionManagementConfiguration.setConfigurers(java.util.Collection); 嵌套exception是org.springframework.beans.factory.BeanCreationException:在类ru.mystamps.web.config.DbConfig中定义名为’entityManagerFactory’的bean时出错:bean的实例化失败; 嵌套exception是org.springframework.beans.factory.BeanDefinitionStoreException:工厂方法[public org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean ru.mystamps.web.config.DbConfig.entityManagerFactory()]抛出exception; 嵌套exception是java.lang.IllegalArgumentException:DataSource不能为null 从web.xml映射: spring.profiles.default dev spring org.springframework.web.servlet.DispatcherServlet contextClass org.springframework.web.context.support.AnnotationConfigWebApplicationContext contextConfigLocation ru.mystamps.web.config.MvcConfig, ru.mystamps.web.config.DbConfig 1 DbConfig.java : @Configuration @EnableTransactionManagement @ImportResource(“classpath:spring/datasource.xml”) public class DbConfig { @Autowired private DataSource dataSource; @Bean public JpaVendorAdapter jpaVendorAdapter() { final HibernateJpaVendorAdapter jpaVendorAdapter = new HibernateJpaVendorAdapter(); jpaVendorAdapter.setDatabasePlatform(dialectClassName); jpaVendorAdapter.setShowSql(showSql); return jpaVendorAdapter; } @Bean […]