小编luk*_*mir的帖子

Spring MVC中的@RequestParam处理可选参数

Spring控制器是否可以处理这两种请求?

1) http://localhost:8080/submit/id/ID123432?logout=true

2) http://localhost:8080/submit/id/ID123432?name=sam&password=543432

如果我定义了这种类型的单个控制器:

 @RequestMapping (value = "/submit/id/{id}", method = RequestMethod.GET,   
 produces="text/xml")
public String showLoginWindow(@PathVariable("id") String id,
                              @RequestParam(value = "logout", required = false) String logout,
                              @RequestParam("name") String username,
                              @RequestParam("password") String password,
                              @ModelAttribute("submitModel") SubmitModel model,
                              BindingResult errors) throws LoginException {...}
Run Code Online (Sandbox Code Playgroud)

不接受带有"注销"的HTTP请求.

如果我定义两个控制器来分别处理每个请求,Spring会抱怨异常"已经有'Controller'bean方法...已映射".

java spring spring-mvc

165
推荐指数
3
解决办法
28万
查看次数

如何避免Maven中的禁止依赖错误?

由于以下错误,我无法构建我的项目:

[WARNING] Rule 6: org.apache.maven.plugins.enforcer.EnforceBytecodeVersion failed with message:
Found Banned Dependency: de.lmu.ifi.dbs.utilities:common-extension-lib:jar:2.4.0
Found Banned Dependency: de.lmu.ifi.dbs.jfeaturelib:JFeatureLib:jar:1.6.1
Use 'mvn dependency:tree' to locate the source of the banned dependencies.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ----------------
Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:1.3.1:enforce (enforce-rules) on project : 
Some Enforcer rules have failed. Look above for specific messages explaining why the rule failed.
Run Code Online (Sandbox Code Playgroud)

我尝试使用,mvn install -Denforcer.skip=true但效果不佳

无法执行目标 org.apache.maven.plugins:maven-compiler-plugin

更新:

我还尝试按如下方式覆盖执行器插件,但错误仍然相同:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-enforcer-plugin</artifactId>
    <executions>
        <execution>
            <id>enforce-banned-dependencies</id>
            <goals>
                <goal>enforce</goal>
            </goals>
            <configuration>
                <rules>
                    <bannedDependencies>
                        <includes> …
Run Code Online (Sandbox Code Playgroud)

java maven

7
推荐指数
1
解决办法
2万
查看次数

如何在Spring中使用application.properties设置配置文件?

我想使用application.properties文件设置配置文件,条目为:

mode=master
Run Code Online (Sandbox Code Playgroud)

如何在我的context.xml文件中设置spring.profiles.active?init-param仅适用于web.xml上下文.

<init-param> 
    <param-name>spring.profiles.active</param-name>
    <param-value>"${mode}"</param-value>
</init-param>
Run Code Online (Sandbox Code Playgroud)

java spring

5
推荐指数
1
解决办法
9437
查看次数

春天Guice提供者的等价性

Guice的提供者在Spring中的等价性是什么?

这是我需要用Spring替换的Guice代码:

public class MyProxyProvider implements Provider<MyProxy> {

@Inject
Config config;

@Override
public MyProxy get() {
    return new MyProxy(httpsclient, config.server, config.user, config.password, config.version);
}
Run Code Online (Sandbox Code Playgroud)

}

这里定义了绑定:

public class MyModule implements Module {

@Override
public void configure(Binder g) {
    g.bind(MyProxy.class).toProvider(MyProxyProvider.class);
}
Run Code Online (Sandbox Code Playgroud)

}

最后,我的目标是使用@Autowired代理对象,如下所示:

public class ConnectionTest {

@Autowired
MyProxy proxy;
Run Code Online (Sandbox Code Playgroud)

}

另请注意,MyProxy类在外部jar文件中无法修改.

java spring guice

4
推荐指数
1
解决办法
5600
查看次数

Mybatis和无效类型

我使用mybatis 3.2.2,PostgreSQL并获得"使用无效类型或值实例化类xxx时出错".调用getPluginId()时会触发异常.这是我的配置:

mapper.xml:

<resultMap type="my.class.plugins.Plugin" id="pluginMap">
    <constructor>
        <idArg column="id" javaType="_int"/>
        <arg column="dtype" javaType="String"/>
    </constructor>

</resultMap>
Run Code Online (Sandbox Code Playgroud)

这是一个有问题的方法:

<select id="getPluginById" resultMap="pluginMap">
SELECT *
FROM public.plugin
WHERE id = #{id, jdbcType=NUMERIC}
</select>   
Run Code Online (Sandbox Code Playgroud)

默认构造函数:

public abstract class Plugin {
...
public Plugin(int id, String name) {
    this.id = id;
    this.name = name;
}
}
Run Code Online (Sandbox Code Playgroud)

一个例外:

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.reflection.ReflectionException: Error instantiating class my.class.plugins.Plugin with invalid types (int,String,) or values (7418,FORWARD,). Cause: java.lang.InstantiationException
at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:73)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:364)
at $Proxy15.selectOne(Unknown Source)
at org.mybatis.spring.SqlSessionTemplate.selectOne(SqlSessionTemplate.java:159) …
Run Code Online (Sandbox Code Playgroud)

java postgresql persistence mybatis

2
推荐指数
2
解决办法
1万
查看次数

Spring Boot中的外部配置和一次性测试

Spring引导具有外部化配置的能力,这意味着you can work with the same application code in different environments.

您可以在jar中捆绑application.properties,它提供合理的默认名称.在生产环境中运行时,可以在jar之外提供覆盖名称的application.properties; 对于一次性测试,您可以使用特定的命令行开关启动:

java -jar app.jar --name="Spring"
Run Code Online (Sandbox Code Playgroud)
  1. 一次性测试实际上意味着什么?
  2. 我怎么样work with the same application code in different environments

java spring properties spring-boot

1
推荐指数
1
解决办法
1002
查看次数