我已经通过在pom.xml中添加插件和spring引导依赖项将一个现有的spring应用程序转换为spring引导应用程序。这是我的pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.9.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- tag::actuator[] -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- end::actuator[] -->
<!-- Spring Security -->
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>3.2.5.RELEASE</version>
</dependency>
<!-- Spring Security -->
<!-- odbc -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.2.0</version>
</dependency>
<!-- odbc -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
下面是我的controller类:
@Controller
@ComponentScan("com.eg.example.controller")
public class HomeController {
private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
@Autowired
private DatabaseDAO dao;
/*some code */
}
public class DatabaseDAO {
/*dao sepcific code*/
}
现在,在运行maven安装之后,jar被构建在目标文件夹中,当我从命令提示符运行jar时,我会收到以下错误:
我无法找出错误在哪里,请帮助我解决这个问题。这是我的servlet-context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean>
<context:component-scan base-package="com.eg.example.*" />
</beans:beans>
您应该在databaseDao
类上面注释@repository
。由于spring上下文无法找到bean名称DatabaseDao将其注入到HomeController
组件中而导致的错误。
pom.xml:
我的SpringBoot应用程序中有一个控制器: 我想在mocks的帮助下,将其与服务分开进行测试。如何实施?
在我的struts 2.3.16.1应用程序中,在web中进行过滤器映射之后。发生xml“未找到资源异常”。甚至web目录中的jsp页面也显示了相同的异常。提前谢谢你的帮助。 struts.xml
我有一个springboot应用程序,它根据LDAP验证身份验证。我通过邮递员测试了它,它工作得很好。我扩展了WebSecurityConfigurerAdapter以根据LDAP验证登录凭据。这是工作很好,没有任何问题。我有一个angular前端,我调用/login,并将用户名和密码发送到它。它没有工作,我得到一个CORs错误。我将下面的代码添加到application.java中,我再也看不到
我有一个spring-boot应用程序,没有任何控制器类。如何为该应用程序编写异常处理程序。用@ControllerAdvice注释的异常处理程序类不起作用。